在Python中将Subject标头添加到server.sendmail() [英] Add Subject header to server.sendmail() in Python
本文介绍了在Python中将Subject标头添加到server.sendmail()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写一个python脚本来从终端发送电子邮件。在我当前发送的邮件中,没有主题。我们如何在此电子邮件中添加主题?
I'm writing a python script to send emails from the terminal. In the mail which I currently send, it is without a subject. How do we add a subject to this email?
我当前的代码:
import smtplib
msg = """From: hello@hello.com
To: hi@hi.com\n
Here's my message!\nIt is lovely!
"""
server = smtplib.SMTP_SSL('smtp.example.com', port=465)
server.set_debuglevel(1)
server.ehlo
server.login('examplelogin', 'examplepassword')
server.sendmail('me@me.com', ['anyone@anyone.com '], msg)
server.quit()
推荐答案
您需要将邮件标题中的主题
。
You need to put the subject
in the header of the message.
示例-
import smtplib
msg = """From: hello@hello.com
To: hi@hi.com\n
Subject: <Subject goes here>\n
Here's my message!\nIt is lovely!
"""
server = smtplib.SMTP_SSL('smtp.example.com', port=465)
server.set_debuglevel(1)
server.ehlo
server.login('examplelogin', 'examplepassword')
server.sendmail('me@me.com', ['anyone@anyone.com '], msg)
server.quit()
这篇关于在Python中将Subject标头添加到server.sendmail()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文