我相信这个问题已经被问过了,但是我找不到任何方法让它工作。
我正在试图向客户发送跟进电子邮件,但我想欺骗电子邮件地址,使发件人地址为我的同事。我在网上读到过,头部中的发件人地址只是一个可以编辑的文本字段,但我仍然无法发送电子邮件。
import smtplib
email_to = '*****@gmail.com'
username = '*******@outlook.com'
password = '*********'
other_email = '*******@outlook.com'
mail = smtplib.SMTP('Outlook.com', 25)
mail.ehlo()
mail.starttls()
mail.login(username,password)
header = ('To:' + email_to + '\n' +'From: ' + other_email + '\n'
+ 'Subject: Python Project Test\n')
message = (header +
'\n\n This is a test message generated from a Python script. \n\n')
mail.sendmail(username, email_to, message)
mail.close()
print("Email sent successfully.")
我知道这是可以做到的,但有人能指点我正确的方向吗?有没有办法让我在发件人字段中伪装我的名称为应该接收此邮件的电子邮件的名称?
===================================
此外,为了完整起见,这是我收到的错误:
Traceback (most recent call last):
File "C:\Users\*****\Desktop\email outlook.py", line 16, in <module>
mail.sendmail(username, email_to, message)
File "C:\Users\*****\AppData\Local\Programs\Python\Python36-32\lib\smtplib.py", line 887, in sendmail
raise SMTPDataError(code, resp)
smtplib.SMTPDataError: (550, b'5.7.60 SMTP; Client does not have permissions to send as this sender')
我希望有一种方法可以使 other_name 成为用户名的别名。