簡體   English   中英

發送給多個接收者的Python 3.4電子郵件引發錯誤

[英]Python 3.4 email to multiple receivers throws an ERROR

我正在編寫一個腳本,以將電子郵件發送到多個電子郵件帳戶,但還不能。

它按下面的方式工作,但是如果我將receivers='xxx@xxx.com','yyy@yyy.com'為無效,則會引發錯誤:

AttributeError: 'tuple' object has no attribute 'encode'. 

如何設置receivers=

def send_email (out_file):

    sender = 'xxx@xxx.com'
    receivers = 'xxx@xxx.com'
    email_pass = 'aaaa'

    filematch=re.findall('NE.*\.txt',out_file.name)

    subject = ("NEXXXX_price_update")
    message = ("The following file was forwarded to your ftp account %s "  %filematch)

    msg = 'Subject: %s\n%s' %(subject, message)


    try:
        smtpObj = smtplib.SMTP_SSL('smtp.gmail.com',0)
        smtpObj.login(receivers, email_pass)
        smtpObj.sendmail(sender, receivers, msg)

        print ("Successfully sent email")

    except SMTPException:        

        print ("email NOT successful")
        print(SMTPException.__cause__)        

        smtpObj.quit() 

您分配錯誤

receivers='xxx@xxx.com','yyy@yyy.com'

您假設將其分配為tuplelist ,但不確定100%是哪一個。

試一下:

receivers=('xxx@xxx.com','yyy@yyy.com')

要么

receivers=['xxx@xxx.com','yyy@yyy.com']

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM