{"id":973,"date":"2020-02-28T11:51:57","date_gmt":"2020-02-28T02:51:57","guid":{"rendered":"https:\/\/www.kwonline.org\/memo2\/?p=973"},"modified":"2020-07-01T22:38:08","modified_gmt":"2020-07-01T13:38:08","slug":"send-mail-from-gce-by-postfix-via-sendgrid","status":"publish","type":"post","link":"https:\/\/www.kwonline.org\/memo2\/2020\/02\/28\/send-mail-from-gce-by-postfix-via-sendgrid\/","title":{"rendered":"GCE:Postfix+SendGrid\u3067\u30e1\u30fc\u30eb\u9001\u4fe1"},"content":{"rendered":"<p>\u5bb6\u306e\u30e1\u30eb\u9bd6\u3092\u30ed\u30ea\u30dd\u304b\u3089GCP\u306b\u79fb\u8a2d\u3057\u305f\u306e\u3067\u30e1\u30e2<\/p>\n<p>\u307e\u305a\u306fCompute Engine\u3067f1-micro\u30de\u30b7\u30f3\u3092\u7acb\u3066\u308b\u3002<br \/>\nOS\u306f\u3044\u3064\u3082\u306eUbuntu 18.04<\/p>\n<h3>\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7<\/h3>\n<p>\u307e\u305a\u306fPostfix+Dovecot\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3002<\/p>\n<p>\u624b\u9806\u306f\u3053\u3061\u3089\u3092\u53c2\u8003\u3002<br \/>\n<a href=\"https:\/\/www.server-world.info\/query?os=Ubuntu_18.04&#038;p=mail&#038;f=1\" rel=\"noopener noreferrer\" target=\"_blank\">Ubuntu 18.04 LTS : Postfix : \u30a4\u30f3\u30b9\u30c8\u30fc\u30eb : Server World<\/a><br \/>\n\u4e0a\u8a18\u30b5\u30a4\u30c8\u306e\u624b\u9806\u3092\u53c2\u8003\u306b\u3057\u3066Postfix\u3001Dovecot\u3001SSL\/TLS\u306e\u8a2d\u5b9a\u307e\u3067\u3084\u3063\u3066\u304a\u304f\u3002<\/p>\n<p>certbot\u306e\u66f4\u65b0\u6642\u306b\u30b5\u30fc\u30d3\u30b9\u3092\u518d\u8d77\u52d5\u3059\u308b\u3088\u3046\u306bcron\u8a2d\u5b9a\u3092\u5909\u3048\u308b\u3002<br \/>\n\u672b\u5c3e\u306b &#8211;deploy-hook\u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u8ffd\u52a0\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n#\/etc\/cron.d\/certbot\r\n0 *\/12 * * * root test -x \/usr\/bin\/certbot -a \\! -d \/run\/systemd\/system &amp;&amp; perl -e 'sleep int(rand(43200))' &amp;&amp; certbot -q renew --deploy-hook &quot;systemctl restart postfix dovecot&quot;\r\n<\/pre>\n<p>\u305d\u3057\u3066GCP\u306eVPC Firewall\u8a2d\u5b9a\u3067\u3001Postfix+Dovecot\u304c\u52d5\u3044\u3066\u308bVM\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306b\u5bfe\u3057\u3066\u4f7f\u7528\u3059\u308b\u30dd\u30fc\u30c8\u3092\u7a74\u3042\u3051\u3057\u3066\u304a\u304f\u4e8b\u3002<br \/>\n\u4eca\u56de\u306e\u8a2d\u5b9a\u3060\u3068\u6700\u4f4e\u9650\u30a4\u30f3\u30d0\u30a6\u30f3\u30c9\u3067 tcp 25, 465, 995\u306a\u3069\u5fc5\u8981\u306a\u3082\u306e\u3092\u3042\u3051\u308b\u3002<\/p>\n<h3>header_checks\u8a2d\u5b9a\u3092\u6709\u52b9\u5316<\/h3>\n<p>\u3064\u3044\u3067\u306bheader_checks\u306e\u8a2d\u5b9a\u3092\u6709\u52b9\u306b\u3057\u3066\u602a\u3057\u3044\u6dfb\u4ed8\u30d5\u30a1\u30a4\u30eb\u4ed8\u304d\u306e\u30e1\u30fc\u30eb\u3092\u30d6\u30ed\u30c3\u30af\u3059\u308b\u8a2d\u5b9a\u3092\u8ffd\u52a0\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n# \/etc\/postfix\/main.cf\r\nheader_checks = regexp:\/etc\/postfix\/header_checks\r\n<\/pre>\n<p>\u305d\u3057\u3066 header_checks \u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u3066\u4fdd\u5b58\u3002<br \/>\n\u30eb\u30fc\u30eb\u306b\u4e00\u81f4\u3057\u305f\u30e1\u30fc\u30eb\u306f\u5168\u3066 DISCARD \u3067\u7834\u68c4\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n# \/etc\/postfix\/header_checks\r\n\/^X-Mailer:.*PostMaster General\/ DISCARD\r\n\/name=.*\\.scr\/ DISCARD\r\n\/name=.*\\.exe\/ DISCARD\r\n\/name=\\&quot;.*\\.inf\\&quot;\/ DISCARD\r\n\/name=\\&quot;.*\\.scr\\&quot;\/ DISCARD\r\n\/name=\\&quot;.*\\.pif\\&quot;\/ DISCARD\r\n\/name=\\&quot;.*\\.bat\\&quot;\/ DISCARD\r\n\/name=\\&quot;.*\\.dll\\&quot;\/ DISCARD\r\n\/name=\\&quot;.*\\.vbs\\&quot;\/ DISCARD\r\n\/name=\\&quot;.*\\.reg\\&quot;\/ DISCARD\r\n\/^Return-Path:.*&lt;#.*@.*&gt;\/ DISCARD\r\n\/^From:.*&lt;#.*@.*&gt;\/ DISCARD\r\n<\/pre>\n<p>header_checks\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u5f8c\u3001postmap\u3067header_checks.db\u3092\u4f5c\u6210\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo postmap \/etc\/postfix\/header_checks\r\n<\/pre>\n<h3>SendGrid\u3078\u306e\u30ea\u30ec\u30fc\u8a2d\u5b9a<\/h3>\n<p>GCE\u306fOP25B\u306b\u3088\u3063\u3066VPC\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u5916\u90e8\u3078\u306etcp25\u756a\u63a5\u7d9a\u304c\u51fa\u6765\u306a\u3044\u3002<br \/>\n\u5916\u90e8\u304b\u3089GCE\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3078\u306etcp25\u756a\u63a5\u7d9a\u306fVPC Firewall\u8a2d\u5b9a\u3092\u958b\u3051\u308c\u3070\u53ef\u80fd\u3002<\/p>\n<p>\u3068\u3044\u3046\u308f\u3051\u3067Postfix\u306erelayhost\u8a2d\u5b9a\u3092\u4f7f\u3063\u3066SendGrid\u306e465\u756a\u30dd\u30fc\u30c8\u7d4c\u7531\u3067\u30e1\u30fc\u30eb\u3092\u9001\u308b\u3002<\/p>\n<p>\u4e0b\u8a18\u3092\u53c2\u8003\u306b\u3057\u3066SendGrid\u3092\u6709\u52b9\u5316\u3059\u308b\u3002<br \/>\n<a href=\"https:\/\/cloud.google.com\/compute\/docs\/tutorials\/sending-mail\/using-sendgrid\" rel=\"noopener noreferrer\" target=\"_blank\">SendGrid \u3067\u306e\u30e1\u30fc\u30eb\u306e\u9001\u4fe1<\/a><br \/>\n\u30ea\u30f3\u30af\u5148\u3067\u306ftcp2525\u756a\u3092\u4f7f\u3063\u3066\u308b\u3051\u3069\u3001SSL\u3092\u4f7f\u3044\u305f\u3044\u306e\u3067tcp465\u756a\u306b\u3057\u305f\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n# \/etc\/postfix\/main.cf\r\nrelayhost = &#x5B;smtp.sendgrid.net]:465\r\nsmtp_sasl_auth_enable = yes\r\nsmtp_sasl_password_maps = hash:\/etc\/postfix\/sasl_passwd\r\nsmtp_sasl_security_options = noanonymous\r\nsmtp_sasl_tls_security_options = noanonymous\r\nsmtp_tls_security_level = encrypt\r\nheader_size_limit = 4096000\r\nsmtp_tls_wrappermode = yes\r\n<\/pre>\n<p>sasl_passwd\u306f\u5148\u7a0b\u306eGCP\u306e\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306e\u3068\u304a\u308a\u4f5c\u6210\u3057\u3066\u304a\u304f\u3002<br \/>\n\u305d\u3057\u3066postfix reload \u3067\u8a2d\u5b9a\u3092\u30ea\u30ed\u30fc\u30c9\u3002<\/p>\n<h3>DNS\u8a2d\u5b9a\u3092\u5909\u66f4<\/h3>\n<p>\u5fd8\u308c\u305a\u306bDNS\u3067VM\u306b\u5bfe\u3059\u308bA\u30ec\u30b3\u30fc\u30c9\u3068\u3001MX\u30ec\u30b3\u30fc\u30c9\u3092\u4f5c\u6210\u3057\u3066\u53cd\u6620\u3092\u5f85\u3064\u3002<\/p>\n<p>\u3055\u3089\u306b\u3001SendGrid\u7d4c\u7531\u3060\u3068\u30e1\u30fc\u30eb\u304c\u5c4a\u304b\u306a\u3044\u30c9\u30e1\u30a4\u30f3\u304c\u3061\u3089\u307b\u3089\u5b58\u5728\u3059\u308b\u306e\u3067\u3001SendGrid\u306bSPF\u8a2d\u5b9a\u3092\u3057\u3066\u304a\u304f\u3002<\/p>\n<p>\u3053\u3061\u3089\u306e\u624b\u9806\u3067 Sender Authentication \u3092\u3059\u308c\u3070OK.<br \/>\n\u6307\u5b9a\u3055\u308c\u305fCNAME\u30ec\u30b3\u30fc\u30c9\u30923\u4ef6DNS\u306b\u8ffd\u52a0\u3059\u308b\u3060\u3051\u3002<br \/>\n<a href=\"https:\/\/sendgrid.com\/docs\/ui\/account-and-settings\/how-to-set-up-domain-authentication\/\" rel=\"noopener noreferrer\" target=\"_blank\">How to set up domain authentication | SendGrid Documentation<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5bb6\u306e\u30e1\u30eb\u9bd6\u3092\u30ed\u30ea\u30dd\u304b\u3089GCP\u306b\u79fb\u8a2d\u3057\u305f\u306e\u3067\u30e1\u30e2 \u307e\u305a\u306fCompute Engine\u3067f1-micro\u30de\u30b7\u30f3\u3092\u7acb\u3066\u308b\u3002 OS\u306f\u3044\u3064\u3082\u306eUbuntu 18.04 \u30bb\u30c3\u30c8\u30a2\u30c3\u30d7 \u307e\u305a\u306fPostfix+Dovecot\u3092\u30a4\u30f3\u30b9\u30c8\u30fc [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-973","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/posts\/973","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/comments?post=973"}],"version-history":[{"count":12,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/posts\/973\/revisions"}],"predecessor-version":[{"id":1202,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/posts\/973\/revisions\/1202"}],"wp:attachment":[{"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/media?parent=973"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/categories?post=973"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/tags?post=973"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}