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

问题描述:

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

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

发送他们作为BCC而不是一个? –

+0

从内存中,它不会让你以这种方式执行BCC,你需要自己创建一个消息并发送原始数据。见下面的答案。 – mouckatron

+0

SES是[每个收件人收费](https://aws.amazon.com/ses/pricing/),而不是每个消息...所以如果您出于成本原因将同一消息发送给多个收件人,吨。 –

我们使用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'] = '[email protected]' 
msg['To'] = '[email protected]' 
msg['Bcc'] = '[email protected]' 

我们使用模板和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())