如何为sendmail添加主题

时间:2013-08-29 01:43:58

标签: python smtp

我使用以下内容使用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()

1 个答案:

答案 0 :(得分:0)

与往常一样,主题只是另一个标题。

msg['Subject'] = subject