我想通过python向我的客户发送邮件通知。问题是需要隐藏发件人邮件帐户。只是要明确-这不是钓鱼或垃圾邮件,只是个人使用!在
我使用了smtplib并在gmail中设置了一个新的“noreply”帐户,但是即使在为邮件提供别名时,“mail from:”头也包含了我的实际邮件。在import smtplib
from email.mime.text import MIMEText
from email.utils import *
email_sender = 'noreply%%@gmail.com'
email_receiver = 'example%%%@gmail.com'
subject = 'Python!'
msg = MIMEText('This is the body of the message.')
msg['To'] = formataddr(('Recipient', 'example%%%@gmail.com'))
msg['From'] = formataddr(('Author', 'author@example.com'))
msg['Subject'] = 'Simple test message'
connection = smtplib.SMTP('smtp.gmail.com', 587)
connection.starttls()
connection.login(email_sender, 'password')
connection.sendmail(msg['From'], email_receiver, msg.as_string())
connection.quit()
我按预期将邮件放入收件箱,但当单击“更多详细信息”时,会显示原始发件人地址。在