Compute Engineからのメール送信2

こんにちは。ヒラヤマンです。

Compute Engineのインスタンスからメール送信を実際に試します。

[root@instance-1 ~]# mail hirayaman@skyarch.net
Subject: message from GCP Instance.
message from GCP Instance.
.
EOT
[root@instance-1 ~]# tail -f /var/log/maillog
Mar 22 05:00:11 instance-1 postfix/postfix-script[1466]: starting the Postfix mail system
Mar 22 05:00:11 instance-1 postfix/master[1467]: daemon started — version 2.6.6, configuration /etc/postfix
Mar 22 05:03:34 instance-1 postfix/pickup[1473]: 4592D80100: uid=0 from=<root>
Mar 22 05:03:34 instance-1 postfix/cleanup[1700]: 4592D80100: message-id=<20170322050334.4592D80100@instance-1.localdomain>
Mar 22 05:03:34 instance-1 postfix/qmgr[1474]: 4592D80100: from=<root@instance-1.localdomain>, size=492, nrcpt=1 (queue active)
Mar 22 05:03:34 instance-1 postfix/smtp[1702]: connect to ASPMX.L.GOOGLE.COM[2607:f8b0:400c:c11::1b]:25: Network is unreachable
Mar 22 05:04:04 instance-1 postfix/smtp[1702]: connect to ASPMX.L.GOOGLE.COM[74.125.134.26]:25: Connection timed out
Mar 22 05:04:04 instance-1 postfix/smtp[1702]: connect to ALT1.ASPMX.L.GOOGLE.COM[2a00:1450:400b:c00::1a]:25: Network is unreachable
Mar 22 05:04:04 instance-1 postfix/smtp[1702]: connect to ALT2.ASPMX.L.GOOGLE.COM[2a00:1450:400c:c07::1b]:25: Network is unreachable
Mar 22 05:04:34 instance-1 postfix/smtp[1702]: connect to ALT2.ASPMX.L.GOOGLE.COM[74.125.133.26]:25: Connection timed out
Mar 22 05:04:34 instance-1 postfix/smtp[1702]: 4592D80100: to=<hirayaman@skyarch.net>, relay=none, delay=61, delays=0.05/0.02/60/0, dsn=4.4.1, status=deferred (connect to ALT2.ASPMX.L.GOOGLE.COM[74.125.133.26]:25: Connection timed out)
^C

外部のメールサーバと25番ポートでは接続できません。

前回紹介したSendGrid社の無料プランに登録して、配信する手順を紹介します。

SendGrid社にアカウント登録完了後に、Compute Engineのインスタンス側(postfix)の設定です

/etc/postfix/main.cfに追記します

relayhost = [smtp.sendgrid.net]:2525
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_security_level = encrypt
header_size_limit = 4096000

続いて/etc/postfix/sasl_passwdを作成します
SendGridIDとPasswordはそれぞれ登録した際のものに置き換えてください

[smtp.sendgrid.net]:2525 SendGridID:Password

最後に2つコマンドを

postmap /etc/postfix/sasl_passwd
/etc/init.d/postfix restart

これでSendGrid社のサーバと2525ポートで接続しメールが中継されます

[root@instance-1 ~]# mail hirayaman@skyarch.net
Subject: message from SendGrid
message from SendGrid
.
EOT
[root@instance-1 ~]# tail -f /var/log/maillog
Mar 22 05:33:27 instance-1 postfix/pickup[2068]: 6E2DD80113: uid=0 from=<root>
Mar 22 05:33:27 instance-1 postfix/cleanup[2090]: 6E2DD80113: message-id=<20170322053327.6E2DD80113@instance-1.localdomain>
Mar 22 05:33:27 instance-1 postfix/qmgr[2069]: 6E2DD80113: from=<root@instance-1.localdomain>, size=482, nrcpt=1 (queue active)
Mar 22 05:33:27 instance-1 postfix/smtp[2071]: certificate verification failed for smtp.sendgrid.net[108.168.190.110]:2525: untrusted issuer /C=US/O=The Go Daddy Group, Inc./OU=Go Daddy Class 2 Certification Authority
Mar 22 05:33:27 instance-1 postfix/smtp[2071]: 6E2DD80113: to=<hirayaman@skyarch.net>, relay=smtp.sendgrid.net[108.168.190.110]:2525, delay=0.16, delays=0.02/0/0.11/0.03, dsn=2.0.0, status=sent (250 Ok: queued as u_ih1eKoT3eI0IeHN_3BLA)
Mar 22 05:33:27 instance-1 postfix/qmgr[2069]: 6E2DD80113: removed

では、また次回

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

Time limit is exhausted. Please reload CAPTCHA.