TOP > 記事一覧 > Google Compute Engineでのメール送信

Google Compute Engineでのメール送信

Google Compute Engineでは、outbound: 25, 465, 587 番ポートは許可されていません。

そのためサーバーからメールを送信するためには

  • クラウドメールサービスを使う。
  • VPNで自社のメールサーバーにつなげて送信する。

といった方法をとる必要があります。
https://cloud.google.com/compute/docs/tutorials/sending-mail/

今回はGoogleが推奨しているクラウドメールサービスを使って送信を試してみました。

  • SendGrid
  • Mailgun

SendGrid

1. SendGrid登録

以下リンクから登録すると、12000/月 送信が無料で使えます。
http://sendgrid.com/partner/google?mbsy=gHNj

2. サーバー設定(postfix)

https://cloud.google.com/compute/docs/tutorials/sending-mail/using-sendgrid

main.cfの編集

root# vi /etc/postfix/main.cf
# default_transport = error
# relay_transport = error
relayhost = [smtp.sendgrid.net]:2525
smtp_tls_security_level = encrypt
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
header_size_limit = 4096000
smtp_sasl_security_options = noanonymous

saslパスワード設定

root# cat > /etc/postfix/sasl_passwd << EOF
[smtp.sendgrid.net]:2525 YOUR_SMTP_LOGIN:YOUR_SMTP_PASSWORD
EOF

↑YOUR_SMTP_LOGIN/YOUR_SMTP_PASSWORDにはSendGridの会員ページにログインし、
[Account Details]のUSERNAME、PASSWORDに記載されているものを入れます。

root# postmap /etc/postfix/sasl_passwd
root# rm /etc/postfix/sasl_passwd
root# chmod 600 /etc/postfix/sasl_passwd.db

最後にpostfixを再起動して完了

root# service postfix restart

Mailgun

1. Mailgun登録

30000/月 送信が無料で使えます。
https://www.mailgun.com/google

2. サーバー設定(postfix)

https://cloud.google.com/compute/docs/tutorials/sending-mail/using-mailgun

main.cfの編集

root# vi /etc/postfix/main.cf
# default_transport = error
# relay_transport = error
relayhost = [smtp.mailgun.org]:2525
smtp_tls_security_level = encrypt
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
header_size_limit = 4096000
smtp_sasl_security_options = noanonymous

saslパスワード設定

root# cat > /etc/postfix/sasl_passwd << EOF
[smtp.mailgun.org]:2525 YOUR_SMTP_LOGIN:YOUR_SMTP_PASSWORD
EOF

↑YOUR_SMTP_LOGIN/YOUR_SMTP_PASSWORDにはMailgunの会員ページにログインし、
[Domain Information]のDefault SMTP Login、Default Passwordに記載されているものを入れます。

root# postmap /etc/postfix/sasl_passwd
root# rm /etc/postfix/sasl_passwd
root# chmod 600 /etc/postfix/sasl_passwd.db

最後にpostfixを再起動して完了

root# service postfix restart

感想

両方のサービス共 簡単に使い始められるので大変便利です。 会員画面では、送信数、状況、ログ等が見れますので、管理もたやすいです。