电子邮件在“收件人与抄送”中不显示收件人

时间:2019-11-24 16:31:00

标签: python python-3.x email smtplib

我正在尝试使用 python 3.8 中的 smtplib 和我的组织交换邮箱(Office 265)发送电子邮件,该电子邮件收发正常了,并且确实可以发送电子邮件了。

但是,电子邮件不会显示带有电子邮件地址的收件人抄送;就像用户正在使用密件抄送发送电子邮件一样发送电子邮件。请帮助


EMAIL_ADDRESS = 'mydept_help@myorg.com'
EMAIL_PASS = None

to = 'myemail@myorg.com'

with smtplib.SMTP('outbound.myorg.com', 25) as smtp:
        smtp.ehlo()
        smtp.starttls()
        smtp.ehlo()

        # smtp.login(EMAIL_ADDRESS,EMAIL_PASS)

        subject = 'Test email'
        body = 'Hello, sending email via python'

        msg = f'Subject: {subject}\n\n{body}'

        smtp.sendmail(EMAIL_ADDRESS, to, msg)

print(msg)```

Please note, our organisation lets us configure dummy emails and there is no authentication required; hence skipped *smtp.login* step

1 个答案:

答案 0 :(得分:1)

您需要在邮件正文中包括以下详细信息作为标题行:

msg = (f'From: {fromaddr}\r\nTo: {toaddr}\r\nsubject: {subject}\r\n\r\n{body}')