问题描述
我在这个问题上遇到了很多时间问题-SO上另一个无法解决的问题在这里:
I'm having big time problems with this issue-- another question on SO that didn't solve it is here: Send Raw Email (with attachment) to Multiple Recipients
(有效的)我的代码很简单:
My code (that works) is simple:
def send_amazon_email_with_attachment(html, subject, now, pre):
dummy = '[email protected]'
recipients = ['[email protected]', '[email protected]', '[email protected]']
connS3 = S3Connection('IDENTIFICATION','PASSWORD')
b = connS3.get_bucket('BUCKET_NAME')
key = b.get_key('FILE_NAME.pdf')
temp = key.get_contents_as_string()
msg = MIMEMultipart('alternative')
msg['Subject'] = subject
msg['From'] = 'My Name <[email protected]>'
msg.preamble = 'Multipart message.\n'
part1 = MIMEText(u"Attached is the report", 'plain')
part2 = MIMEText(html, 'html')
msg.attach(part1)
msg.attach(part2)
part = MIMEApplication(temp) #read binary
part.add_header('Content-Disposition', 'attachment', filename='FILE_NAME.pdf')
msg.attach(part)
conn = boto.ses.connect_to_region('us-east-1', aws_access_key_id='AUTH_ID', aws_secret_access_key='AUTH_PW')
for recipient in recipients:
print recipient
msg['To'] = recipient
result = conn.send_raw_email(msg.as_string(), source=msg['From'], destinations=recipient)
但是,有一个警告...正在为每个收件人循环播放.此的任何变体均不起作用.将列表传递给msg['Bcc']
或msg['BCC']
将返回无法删除列表的错误(与发布的问题完全相同的错误).传递以逗号分隔的字符串会导致Amazon SES问题,在返回的XML中显示非法电子邮件".因为我只是在特定情况下从Amazon得到一个错误,所以我被认为这是程序在到达其API调用之前的一个错误.
but, there's a caveat... this is looping for each recipient. Any variation of this does not work. Passing a list to msg['Bcc']
or msg['BCC']
will return an error that the list can't be stripped (same exact error as the posted question). Passing a string separated by commas gives an Amazon SES issue saying 'Illegal Email' in the returned XML. Because I only get an error from Amazon in specific situations, I'm led to believe this is an error with the program before it hits their API call.
任何MIMEMultipart
专家有什么想法吗?
Any MIMEMultipart
experts have some ideas?
推荐答案
基本上,您需要使用2种不同的格式在2个不同的位置指定电子邮件收件人.
Basically you need to specify the email recipients in 2 different places using 2 different formats.
def send_amazon_email_with_attachment(html, subject, now, pre):
dummy = '[email protected]'
recipients = ['[email protected]', '[email protected]', '[email protected]']
connS3 = S3Connection('IDENTIFICATION','PASSWORD')
b = connS3.get_bucket('BUCKET_NAME')
key = b.get_key('FILE_NAME.pdf')
temp = key.get_contents_as_string()
msg = MIMEMultipart('alternative')
msg['Subject'] = subject
msg['From'] = 'My Name <[email protected]>'
msg['To'] = ', '.join(recipients)
msg.preamble = 'Multipart message.\n'
part1 = MIMEText(u"Attached is the report", 'plain')
part2 = MIMEText(html, 'html')
msg.attach(part1)
msg.attach(part2)
part = MIMEApplication(temp) #read binary
part.add_header('Content-Disposition', 'attachment', filename='FILE_NAME.pdf')
msg.attach(part)
conn = boto.ses.connect_to_region('us-east-1', aws_access_key_id='AUTH_ID', aws_secret_access_key='AUTH_PW')
result = conn.send_raw_email(msg.as_string(), source=msg['From'], destinations=recipients)
这篇关于Boto SES-send_raw_email()到多个收件人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!