我正在使用以下内容使用 smtp 发送电子邮件。但是电子邮件中缺少主题,如何添加主题?
from email.mime.text import MIMEText
from smtplib import SMTP
def email (body,subject):
msg = MIMEText("%s" % body)
msg['Content-Type'] = "text/html; charset=UTF8"
s = SMTP('localhost',25)
s.sendmail('userid@company.com', ['userid@company.com'],msg=msg.as_string())
def main ():
# open gerrit.txt and read the content into body
with open('gerrit.txt', 'r') as f:
body = f.read()
subject = "test email"
email(body)
print "Done"
if __name__ == '__main__':
main()