Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
299 views
in Technique[技术] by (71.8m points)

python - Amazon SES - Hide recipient email addresses

I am testing Amazon SES through boto3 python library. When i send emails i see all the recipient addresses. How to hide these ToAddresses of multiple email via Amazon SES ?

enter image description here

Following is the part of the code

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
)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

We use the send_raw_email function instead which gives more control over the make up of your message. You could easily add Bcc headers this way.

An example of the code that generates the message and how to send it

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]'

We use templating and MIMEText to add the message content (templating part not shown).

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

Then send using the SES send_raw_email().

ses_conn.send_raw_email(msg.as_string())

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...