我正在使用以下代码通过电子邮件发送 gerrit.txt 的内容,这是 HTML 代码,但它不起作用?它没有显示任何错误,但没有按预期的方式工作。关于如何解决这个问题的任何输入?
from email.mime.text import MIMEText
from subprocess import check_call,Popen,PIPE
def email (body,subject,to=None):
msg = MIMEText("%s" % body)
msg['Content-Type'] = "text/html;"
msg["From"] = "userid@company.com"
if to!=None:
to=to.strip()
msg["To"] = "userid@company.com"
else:
msg["To"] = "userid@company.com"
msg["Subject"] = '%s' % subject
p = Popen(["/usr/sbin/sendmail", "-t"], stdin=PIPE)
def main ():
Subject ="test email"
email('gerrit.txt',Subject,'userid')
if __name__ == '__main__':
main()