0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【備忘】boto3・SESでメール送信

Last updated at Posted at 2024-02-14

はじめに

boto3を利用してSESでメール送信処理を実行することが多々あり、
備忘録として記録します!

htmlのテンプレートを使用して送信します。

コード

ses.py
ses_client = boto3.client("ses")

# 諸々設定
sender_name = "送信者"
from_email = "from@email.com"
to_email = "to@email.com"
bcc_email = "bcc@email.com"
mail_subject = "メールタイトル"
mail_content = EMAIL_CONTENT

response = ses_client.send_email(
    Source='%s <%s>'%(Header(sender_name.encode('iso-2022-jp'),'iso-2022-jp').encode(),from_email),
    Destination={
        "ToAddresses": [
            to_email,
        ],
        'BccAddresses': [
            bcc_email,
        ]
    },
    Message={
        "Subject": {
            "Data": mail_subject,
            "Charset": "UTF-8"
        },
        "Body": {
            "Html": {
                "Data": mail_content,
                "Charset": "UTF-8"
            }
        }
    }
)
logger.info("response: {}".format(response))

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?