Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
284 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 Answer

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())

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...