Python SMTP电子邮件来自标头

问题描述

我正在尝试将短消息发送到给定的电子邮件ID,如下所示:

def send_email(policynum,premium,date,name,email):
        port = 465
        smtp_server = "smtp.gmail.com"
        sender_email = "[email protected]"
        receiver_email = email
        password = "brownie2003"
        message = """\Subject:

        To %s,Your Payment to Tirth Insurance 4 Life towards payment of %s for policy number %s on '%s' is SUCCESSFUL.
        Thank You."""%(name,policynum,date)

        context = ssl.create_default_context()        
        with smtplib.SMTP_SSL(smtp_server,port,context=context) as server:
            server.login(sender_email,password)
            server.sendmail(sender_email,receiver_email,message)

注意:您可以看到我在“ receiver_email”旁边写了“ email”。 “ email”是一个变量,其中包含客户的电子邮件地址。

问题是这些邮件被阻止了。我已经关闭了“禁用不太安全的选项”。

给出的原因是因为我的消息没有在电子邮件正文中打印,而是整个消息都在电子邮件的“发件人”标题中打印。

有人可以指出为什么邮件在发件人标题下吗?

谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)