👋
【Azure Communication Service】- メールの送信を試す
執筆日
2024/01/09
やること
Azure Communication Serviceのメール機能を試します。
セットアップ手順
- Azure Communication Servicesを構築する
- Email Communication Servicesを構築する
- 左タブのメール>メールを試すをクリックする
-
無料のAzureサブドメインを設定するをクリックする
- 2構築したEmail Communication Servicesを選択し、作成とアクティブ化をクリックする
- 左タブのメール>ドメインをクリックする
-
ドメインを接続するをクリックする
- 2構築したEmail Communication Servicesを選択し、確認済みのドメインを選択する。
-
接続をクリックする
試す
- 左タブのメール>メールを試すをクリックする
- メールの送信元、受信者のメールアドレスを設定し、sendをクリックする
- メールが届いていることを確認する
- codeで実行する
pip install azure-communication-email
main.py
from azure.communication.email import EmailClient
def main():
try:
connection_string = "ACSの接続文字列"
client = EmailClient.from_connection_string(connection_string)
message = {
"senderAddress": "取得したメールアドレス",
"recipients": {"to": [{"address": "送信したメールアドレス"}]},
"content": {
"subject": "テスト メール",
"plainText": "メールで Hello World。",
"html": """
<html>
<body>
<h1>メールで Hello World。</h1>
</body>
</html>""",
},
}
poller = client.begin_send(message)
result = poller.result()
print("メールを送信しました。")
except Exception as ex:
print(ex)
main()
カスタムドメインの設定手順
料金
従量課金制になります。料金の観点が2つあり、メール1通と1MB単位で発生します。
2025/1/9時点で、メール1通あたり$0.00025、1MBあたり$0.00012という価格になっています。
Discussion