我有一個小代碼可以在 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()
uj5u.com熱心網友回復:
改變
message = "Hello World"
至:
subject = "My subject"
body = "Hello World"
message = f"Subject: {subject}\n\n{body}"
祝你好運。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/516114.html
