Python:电子邮件地址不可见

时间:2018-03-15 17:43:10

标签: python email smtp

我正在尝试向多人发送电子邮件。我的代码正在运行,人们正在收到电子邮件,但不知何故,To:字段显示为"未公开的收件人"在电子邮件客户端,我怎样才能在那里看到它们?

还有什么方法可以在这里添加BCC吗?

这是我的代码:

    from datetime import datetime
    from email.mime.text import MIMEText as text
    import smtplib
    import shutil
    import sys, traceback
    from email.MIMEMultipart import MIMEMultipart


    lines = ['xyz: test@example.com, xyz1: test1@example.com, HJH: 
    test9@example.com, TESTING: gtest1@example.com, GHT: test1@example.com, TYR: 
    test1@example.com', 'GHZ: test8@example.comm, NUY: test5@example.com']
    w1=[]
    sender = ['xyz@example.com']
    for l in lines:
            to = {}
            body = []
            groups = []
            parts = re.split('(.+?)\:\s+([a-zA-Z0-9@\._\-]+),\s+(.*)$', l)
            master = parts[1]
            master_email = parts[2]
            subgroups_line = parts[3]
    subgroup_parts = re.split(',\s*', subgroups_line)
    to[master_email] = 1;
    for sp in subgroup_parts:
        (subgroup_name, subgroup_email) = sp.split(': ')
        groups.extend((subgroup_name,":",subgroup_email+"\n"))
        to[subgroup_email] = 1
                var1 = ''.join(groups)
#                print var1
        print 'email to: ' + ','.join(to.keys())
        receivers =(to.keys())
        header = 'To:' + ",".join(receivers)
        template1=open('template1','r')
        template2=open('template2','r')
        print groups 
        print master
        if master in groups:
          m=text("ANY TEXT1)
        else: 
          m=text("ANY TEXT2")
        m['Subject'] = 'XXXXXXXX'
        try:
          smtpObj = smtplib.SMTP('localhost')
          smtpObj.sendmail(sender, receivers,  m.as_string())
          template1.close()
          template2.close()
        except smtplib.SMTPException:
          print "Unable to send email"

更新: 我能够添加To:以及BCC:功能。请忽略这一点: - )

无论如何,感谢您的帮助!

0 个答案:

没有答案