我尝试按以下方式发送电子邮件,代码中包含html字符串"<html><b><u>" +key + "</u></b></html>"
,因此该电子邮件包含相同的HTML代码而不是HTML格式,我添加了msg["Content-Type"] = "text/html"
,但没有帮助,任何人都可以提供有关修复方法的指南吗?
import os,smtplib
import subprocess,pprint,shlex
from subprocess import Popen, PIPE, call
from email.mime.text import MIMEText
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email import encoders
def sendEmail(type,data):
global originalchange
global gerriturl,email,username
body = '''%s''' % (data)
#msg = MIMEMultipart(body)
msg = MIMEMultipart()
# sender = 'techci@company.com'
sender = 'username@company.com'
receivers = ['username@company.com']
#sendEmail(data)
attachment_file_path = '/Users/username/tech-ci/tools/cloning_change/tech_projects/tech-ci/.git/rebase-apply/patch'
if type =='cherrypickfailure':
msg['Subject'] = 'CHERRYPICK FAILED '
msg['From'] = sender
msg['To'] = ', '.join(receivers)
msg["Content-Type"] = "text/html"
try:
mail = smtplib.SMTP('relay.company.com', 25)
msg.attach(MIMEText(body, 'text/html'))
mail.sendmail(sender, receivers, msg.as_string())
print 'Email sent successfully'
except Exception as e:
print e
conflictedblocks = {'README': '<<<<<<< HEAD\nTRP\n=======\nTBD\n>>>>>>> <rdar://problem/42841519> Dummy change\n'}
conflictedblocks_string = ""
for key,value in conflictedblocks.items():
conflictedblocks_string += "<html><b><u>" +key + "</u></b></html>" +":" + "\n" + value + "\n"
sendEmail('cherrypickfailure',conflictedblocks_string)