我有以下发送电子邮件的代码,问题是CC
选项似乎不起作用,这意味着CC
组中的人没有收到电子邮件,因为我更改了测试组到To
的列表中就可以了,那么如何解决此问题的任何指导?
from email.mime.text import MIMEText
from email.MIMEMultipart import MIMEMultipart
import smtplib
def sendEmail2(type,data):
email ='username@company.com'
body = '''%s''' % (data)
msg = MIMEMultipart()
sender = 'techci@company.com'
receivers = []
cc = ['team-tech-integrators@group.company.com']
REPLY_TO_ADDRESS = 'team-tech-integrators@group.company.com'
if type =='OPERATIONfailure':
b = '\U0001F6A8'
receivers.append(email)
msg['Subject'] = '%s AUTO OPERATION FAILED FOR GERRIT :PLEASE TAKE IMMEDIATE ACTION!!!'%(b.decode('unicode-escape'))
elif type == 'git_push_success':
b = '\U0001F600'
receivers = ['team-tech-integrators@group.company.com']
msg['Subject'] = '%s AUTO OPERATION SUCCESS FOR !!!'%(b.decode('unicode-escape'))
msg['From'] = sender
msg['To'] = ', '.join(receivers)
msg['Cc'] = ','.join(cc)
msg["Content-Type"] = "text/html"
try:
mail = smtplib.SMTP('relay.company.com', 25)
msg.attach(MIMEText(body, 'html'))
msg.add_header('reply-to', REPLY_TO_ADDRESS)
mail.sendmail(sender, receivers, msg.as_string())
except Exception as e:
print e
print "Problem sending email"
def main():
data = "test"
sendEmail2("OPERATIONfailure",data)
if __name__ == "__main__":
main()