【发布时间】: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