我想發送到多個電子郵件,但我收到了這個問題 ValueError('Invalid address "%s"' % addr) ValueError: Invalid address "['[email protected]', '[email protected]', 'ex404@gmail .com']"
email_id = ["[email protected]","[email protected]","[email protected]"]
username = name
email = email_id
######################### mail system ####################################
htmly = get_template('email/Email.html')
d = {
's_id' : s_id,
'username': username,
'tran_id' : tran_id,
'amount' : amount
}
subject, from_email, to = 'welcome', '[email protected]', email
html_content = htmly.render(d)
msg = EmailMultiAlternatives(subject, html_content, from_email, [to])
msg.attach_alternative(html_content, "text/html")
msg.send()
uj5u.com熱心網友回復:
您將陣列型別發送到另一個陣列,因此陣列維度已更改。請像這樣檢查。
email_id = ["[email protected]","[email protected]","[email protected]"]
username = name
email = email_id
######################### mail system ####################################
htmly = get_template('email/Email.html')
d = {
's_id' : s_id,
'username': username,
'tran_id' : tran_id,
'amount' : amount
}
subject, from_email, to = 'welcome', '[email protected]', email
html_content = htmly.render(d)
msg = EmailMultiAlternatives(subject, html_content, from_email, to)
msg.attach_alternative(html_content, "text/html")
msg.send()
uj5u.com熱心網友回復:
正如其他人指出的那樣,您不應該to用方括號括起來,因為它已經是一個字串串列,這正是引數所期望的。看這個例子:
msg = EmailMultiAlternatives("subject", html_content, "from@@gmail.com", ["to@@gmail.com", "to2@@gmail.com", "to3@@gmail.com"])
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/337577.html
標籤:姜戈
