DEV Community

Yasuhiro Matsuda for AWS Community Builders

Posted on

1

CLIでメールを送信する

aws ses send-email --from "送信元アドレス" --to "送信先アドレス" --subject "件名" --text "本文"

ヘッダを変更したい場合などにおいては、aws ses send-raw-emailコマンドを利用する必要があるが、Base64でエンコードしないと Invalid base64 で怒られたりするので少しテクニックが必要となる。

公式ドキュメントにもサンプルが掲載されていなかったので、サンプルを作成してみた。

message.txtとして以下のようなものを用意した上で

{
"Data": "From: (送信元アドレス)\nTo: (Delivered-Toヘッダとしての送信先アドレス)\nSubject: (件名)\n\n(本文)"
}
Enter fullscreen mode Exit fullscreen mode

以下の通りコマンドを実行すれば良い。
なお、message.txtに送信元アドレスを追加しない場合には、 --source "送信元アドレス" を追加する必要がある。(An error occurred (InvalidParameterValue) when calling the SendRawEmail operation: Missing required header 'From'.がエラーが返される)

aws ses send-raw-email --destinations "送信先アドレス1" "送信先アドレス2" --cli-binary-format raw-in-base64-out --raw-message file://message.txt

Top comments (0)

Best Practices for Running  Container WordPress on AWS (ECS, EFS, RDS, ELB) using CDK cover image

Best Practices for Running Container WordPress on AWS (ECS, EFS, RDS, ELB) using CDK

This post discusses the process of migrating a growing WordPress eShop business to AWS using AWS CDK for an easily scalable, high availability architecture. The detailed structure encompasses several pillars: Compute, Storage, Database, Cache, CDN, DNS, Security, and Backup.

Read full post