SMTP APIでは、SendGrid独自のX-SMTPAPIヘッダをメッセージに付与することで、SMTPによるメール送信機能を拡張することができます。具体的には、複数の宛先アドレスへの一斉配信やカテゴリの付与、宛先ごとの文字列の置換などに利用します。
X-SMTPAPIヘッダはJSON文字列として指定します。SMTP APIを利用して複数の宛先アドレスへメール送信するtelnetコマンドの例は以下の通りです。
> telnet smtp.sendgrid.net 587 220 SG ESMTP service ready at geopod-ismtpd-2-1 > EHLO example.com 250-smtp.sendgrid.net 250-8BITMIME 250-PIPELINING 250-SIZE 31457280 250-STARTTLS 250-AUTH PLAIN LOGIN 250 AUTH=PLAIN LOGIN > auth login 334 VXNlcm5hbWU6 > YXBpa2V5 # 固定文字列「apikey」をBASE64エンコードした文字列 334 UGFzc3dvcmQ6 > ******** # APIキーをBASE64エンコードした文字列 235 Authentication successful > mail from: from@example.com 250 Sender address accepted > rcpt to: to@example.com 250 Recipient address accepted > data 354 Continue > x-smtpapi: {"to":["person1@example.com","person2@example.com"]} > From: from@example.com > Subject: test mail > > This is body of the message. > . 250 Ok: queued as ******** |
このコマンドを実行すると、X-SMTPAPIヘッダで指定したperson1@example.comとperson2@example.com宛にメール送信します。
ただし、送信元のドメインもしくはメールアドレスで、Domain AuthenticationまたはSingle Sender Veriification(Sender登録)の設定を行わなければ、メールを送信することができません。こちらをご確認のうえ必ず設定してください。
その他機能の詳細はAPIリファレンスをご覧ください。