【问题标题】:Python email sendingPython 电子邮件发送
【发布时间】:2022-10-13 00:56:34
【问题描述】:

我有一个小代码可以在 python 中发送电子邮件。但是,我想分别定义消息主题和消息主体。但是,“发送邮件功能”不接受“主题”输入。请告知。Tnx

host = "smtp.gmail.com"
port = 465
sender_email = "*****@gmail.com"
password = "****"
receiver_email = "****@gmail.com"
subject = "Test email"
message = "Hello World"

try:
  smtp_ssl = smtplib.SMTP_SSL(host, port)
except Exception as e:
  smtp_ssl = None

resp_code, response = smtp_ssl.login(sender_email, password)                     
smtp_ssl.sendmail(from_addr = sender_email, to_addrs = receiver_email, msg = message)  
resp_code, response = smtp_ssl.quit()

【问题讨论】:

    标签: python-3.x email send


    【解决方案1】:

    改变

    message = "Hello World"
    

    至:

    subject = "My subject"
    body = "Hello World"
    message = f"Subject: {subject}
    
    {body}"
    

    祝你好运。

    【讨论】:

      【解决方案2】:

      谢谢阿图拉斯。现在它工作正常。

      【讨论】:

        猜你喜欢
        • 2018-06-09
        • 1970-01-01
        • 2021-04-26
        • 2019-10-18
        • 2012-06-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多