Amazon SES - 隐藏收件人电子邮件地址

时间:2016-08-02 14:01:19

标签: python python-2.7 amazon-web-services amazon-ses boto3

我正在通过boto3 python库测试Amazon SES。当我发送电子邮件时,我会看到所有收件人地址。如何通过Amazon SES隐藏多个电子邮件的这些ToAddresses?

enter image description here

以下是代码的一部分

import boto3
client=boto3.client('ses')
to_addresses=["**@**","**@**","**@**",...]

response = client.send_email(
    Source=source_email,
    Destination={
        'ToAddresses': to_addresses
    },
    Message={
        'Subject': {
        'Data': subject,
        'Charset': encoding
        },
        'Body': {
            'Text': {
                'Data': body ,
                'Charset': encoding
            },
            'Html': {
                'Data': html_text,
                'Charset': encoding
            }
        }
    },
    ReplyToAddresses=reply_to_addresses
)

1 个答案:

答案 0 :(得分:0)

我们使用send_raw_email函数,它可以更好地控制邮件的构成。您可以通过这种方式轻松添加Bcc标题。

生成消息的代码示例以及如何发送消息

from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

msg = MIMEMultipart('alternative')
msg['Subject'] = 'Testing BCC'
msg['From'] = 'no-reply@example.com'
msg['To'] = 'user@otherdomain.com'
msg['Bcc'] = 'hidden@otherdomain.com'

我们使用模板和MIMEText来添加消息内容(模板部分未显示)。

part1 = MIMEText(text, 'plain', 'utf-8')
part2 = MIMEText(html, 'html', 'utf-8')
msg.attach(part1)
msg.attach(part2)

然后使用SES send_raw_email()发送。

ses_conn.send_raw_email(msg.as_string())