0

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

1 回答 1

0

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

msg['Subject'] = subject
于 2013-08-29T01:48:32.560 回答