如何使用boto3 ses连接发送多个电子邮件附件?

时间:2018-01-23 02:24:16

标签: python email boto3 mime amazon-ses

以下代码通过带有1个附件的SES发送带有boto3的电子邮件。如何更改代码以发送2封电子邮件* .csv附件。

mail.py

client = boto3.client('ses',region_name='us-east-1')
MESSAGE = 'From: '+SENDER+'\n'
MESSAGE = MESSAGE + 'To: '+RECIPIENT+'\n'
MESSAGE = MESSAGE + 'Subject: '+SUBJECT+'\n'
MESSAGE = MESSAGE + 'MIME-Version: 1.0\n'
MESSAGE = MESSAGE + 'Content-type: Multipart/Mixed; boundary="NextPart"\n\n'
MESSAGE = MESSAGE + '--NextPart\nContent-Type: text/plain\n\n'+BODY_TEXT+'\n\n'
MESSAGE = MESSAGE + '--NextPart\nContent-Type: text/plain;\n'
MESSAGE = MESSAGE + 'Content-Disposition: attachment; filename="attachment.txt"\n\n'
MESSAGE = MESSAGE + 'This is the text in the attachment.\n\n'
MESSAGE = MESSAGE + '--NextPart--\n'
MESSAGE = MESSAGE + 'Content-type: Multipart/Mixed; boundary="NextPart"\n\n'
MESSAGE = MESSAGE + '--NextPart\n'
MESSAGE = MESSAGE + 'Content-Type: text/plain\n\n'
MESSAGE = MESSAGE + BODY_TEXT+'\n\n'
MESSAGE = MESSAGE + '--NextPart\n'
MESSAGE = MESSAGE + 'Content-Type: text/plain;\n'
MESSAGE = MESSAGE + 'Content-Disposition: attachment; filename="attachment.txt"\n\n'
MESSAGE = MESSAGE + 'This is the text in the attachment.\n\n--NextPart--'

RAW_MESSAGE = {
    'Data': MESSAGE
}
response = client.send_raw_email(
    Destinations=[RECIPIENT,],
    RawMessage=RAW_MESSAGE,
    Source=SENDER
)

0 个答案:

没有答案