使用Python“ smtplib”模块发送的电子邮件为空

问题描述

问题::当我发送电子邮件时,它确实从[email protected]发送到[email protected],但电子邮件为空。但是,当我使用Gmail发送电子邮件时,电子邮件内容一起到达。

@app.route('/')
        def email():
            msg= 'Hello'
            server = smtplib.SMTP("smtp-mail.outlook.com",587)
            server.starttls()
            server.login("[email protected]","Password1")
            server.sendmail("[email protected]","[email protected]",msg)
            return 'Message Sent!'

理想的结果:当我在[email protected]中打开电子邮件时,我想查看内容

解决方法

我无法测试,但可能有必要添加

"From: [email protected]\r\nTo: [email protected]\r\n\r\n"

msg的开头。

所以我会尝试

msg = 'From: [email protected]\r\nTo: [email protected]\r\n\r\nHello'

看看效果是否更好。

与Hotmail相比,Gmail在这些方面可能更宽容。

还要注意“ Hello”之前的空白行(\r\n\r\n)。