Postfix+SendGridその2

作業記録

SendGridがどういうものなのかざっくり理解したので、早速使えるようにしてみます。
今回は(さくらVPSの)CentOS7からSendGrid経由でメールを送付できるかの確認まで。
APIでの送付は次回やります。

SendGrid申し込み

さくらVPSコンパネへログイン

SendGridのお申し込み をクリック

SendGridへ(外部サービスへ移動) をクリック

特典付会員登録 をクリック

メールアドレス※アカウント登録用メールアドレス

確認メールを送信する

【SendGrid】仮登録完了のお知らせ が届く

メールのリンク先から本登録をする※いろいろと質問されるが、要するにスパムに利用しないよね?というお話

【SendGrid】本登録完了のお知らせ が届く

このメールに、遅くとも翌営業日までにご登録内容確認しログイン情報をお知らせします、と物騒なことが書いてあった。
急いでいたので相当失望したが、40分後くらいにはSendGridのログイン情報が届いた。

メールのリンク先からSendGridにログイン
ーーーーー
マイページ
ご利用状況
ユーザ名 *@sakura.kke.com
ご利用中のプラン Freeプラン(さくらのクラウド、さくらのVPS)
ーーーーー

ちょっと覚えていないが連絡先のメールアドレス確認のため、再度メール受信してそのメールからリンク先に飛ぶ、という作業をやった。
マスト作業なのかどうかは不明。これが終わるとダッシュボート左上の名前が自分の名前に変わった(と思う)。

APIキー作成

左メニューの「Settings」をクリック

「API Keys」をクリック

Create API Keyをクリック

API Key Name 任意
API Key Permissions Full Access

Create&View

APIキーが作成されるので必ずコピーするなり保存する

メール送付(失敗)

・さくらVPSのサーバにログイン

cp -ai /etc/postfix/main.cf /etc/postfix/main.cf.0
vi /etc/postfix/main.cf
-----
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous
smtp_tls_security_level = encrypt
header_size_limit = 4096000
relayhost = [smtp.sendgrid.net]:587
-----

cp -ai /etc/postfix/master.cf /etc/postfix/master.cf.0
vi /etc/postfix/master.cf
-----
(変更)
#submission inet n       -       n       -       -       smtpd
↓
submission inet n       -       n       -       -       smtpd
-----

vi /etc/postfix/sasl_passwd
-----
[smtp.sendgrid.net]:587 apikey:*****************************************************(APIキー)
-----

sudo chmod 600 /etc/postfix/sasl_passwd
sudo postmap /etc/postfix/sasl_passwd

sudo systemctl restart postfix

yum install cyrus-sasl-plain

まだ送付できない。

echo -e "slave port143 Connection refused." | mail -s "slave port143 Connection refused." -r ****@********(送付元アドレス) ****@********(送付先アドレス)
-----
Jul 18 18:52:48 ik1-425-44556 postfix/smtp[23538]: BCABD805058: to=<****@********>, relay=smtp.sendgrid.net[169.38.103.42]:587, delay=1065, delays=1063/0.02/1/0.78, dsn=5.0.0, status=bounced (host smtp.sendgrid.net[169.38.103.42] said: 550 The from address does not match a verified Sender Identity. Mail cannot be sent until this error is resolved. Visit https://sendgrid.com/docs/for-developers/sending-email/sender-identity/ to see the Sender Identity requirements (in reply to end of DATA command))
-----

差出人情報(Sender)の認証

差出人情報(Sender)の認証を完了する必要がある。
https://support.sendgrid.kke.co.jp/hc/ja/articles/360000158641-%E5%B7%AE%E5%87%BA%E4%BA%BA%E6%83%85%E5%A0%B1-Sender-%E3%81%AE%E8%AA%8D%E8%A8%BC%E3%81%8C%E5%AE%8C%E4%BA%86%E3%81%97%E3%81%BE%E3%81%9B%E3%82%93-%E3%81%A9%E3%81%86%E3%81%99%E3%82%8C%E3%81%B0%E3%82%88%E3%81%84%E3%81%A7%E3%81%97%E3%82%87%E3%81%86%E3%81%8B-

https://sendgrid.kke.co.jp/docs/Tutorials/B_Marketing_Mail/marketing_campaigns1.html

「Marketing」 → 「Create New Sender」から必要な情報を入力し、届いたメールから確認を済ませる

メール送付(成功)

echo -e "slave port143 Connection refused." | mail -s "slave port143 Connection refused." -r ****@********(送付元アドレス) ****@********(送付先アドレス)

送付できた!

前の記事

Postfix+SendGrid