※こちらは旧サイトです(新サイトはこちら)
SendgridでAPIが提供されてたので使ってみたメモ
公式からは、sendgridパッケージが提供されててこちらの利用を推奨との事ですが、Githubにあったサンプルがそのままでは動かなかったので、今回は時間の都合上、requestsで単純なPOSTを投げる方で実装しました。以下、その手順
$ python --version
Python 3.6.2
$ pip install requests
$ pip freeze | grep requests
requests==2.18.4
$ vim send.py
import requests
APIKEY="[API Key]"
headers = {
"Authorization": "Bearer "+APIKEY
}
payload = {
"to": "to@example.com",
"from": "from@example.com",
"subject": "タイトル",
"html": "本文"
}
r = requests.post("https://api.sendgrid.com/api/mail.send.json", headers=headers, params=payload)
$ python send.py