事象・問題
サーバーにインストールしたGitLabからAWS SESを使ってメールを送りたいのですが、うまくメールを送信できません
・公式サイトを見て、コンテナ内の設定ファイル(/etc/gitlab/gitlab.rb)に、 SMTP 認証情報 や ドメインを記述しました。
送信元メールアドレスの作成などのアドレスを新しく作る必要などあるのでしょうか?
ポート 25 の制限を削除する必要はあるのでしょうか?
GitLabのユーザー登録時のメール送信が失敗したときにバウンスメールも受信できなていないので、gitlab.rbの記述に誤りがあるのではないかと考えています。
インフラ、サーバー運用にお詳しい方、ご教授のほどお願いいたします。
※必要だと思う情報は載せてるつもりですが知りたい設定情報などがございましたら仰ってください。
/etc/gitlab/gitlab.rb
公式のメール設定の欄(AWS SESのポート587の方)を参考に編集しました。
smtp_address:Amazon SES > SMTP 設定 画面内の SMTP エンドポイント(リージョンは東京)
smtp_user_name:Amazon SES > SMTP 設定 画面からDLしたSMTP 認証情報(credentials.csv)のSmtp Usernameの値
smtp_password:Amazon SES > SMTP 設定 画面からDLしたSMTP 認証情報(credentials.csv)のSmtp Passwordの値
smtp_domain:Amazon SES > 設定: 検証済み ID画面で登録した検証済みID(Route53で取得したドメインと同値)
### GitLab email server settings ###! Docs: https://docs.gitlab.com/omnibus/settings/smtp.html ###! **Use smtp instead of sendmail/postfix.** #################### 下記を編集 (smtp_pool以外) ######################### gitlab_rails['smtp_enable'] = true gitlab_rails['smtp_address'] = "email-smtp.ap-northeast-1.amazonaws.com" gitlab_rails['smtp_port'] = 587 gitlab_rails['smtp_user_name'] = "XXXXXXXXXXX4ZTEAH5" gitlab_rails['smtp_password'] = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXeoOj6Q14uVy1iE" gitlab_rails['smtp_domain'] = "XXXX-dev-1.com" gitlab_rails['smtp_authentication'] = "login" gitlab_rails['smtp_enable_starttls_auto'] = true gitlab_rails['smtp_tls'] = true # gitlab_rails['smtp_pool'] = false #################### 上記を編集 ################################## ###! **Can be: 'none', 'peer', 'client_once', 'fail_if_no_peer_cert'** ###! Docs: http://api.rubyonrails.org/classes/ActionMailer/Base.html # gitlab_rails['smtp_openssl_verify_mode'] = 'none' # gitlab_rails['smtp_ca_path'] = "/etc/ssl/certs" # gitlab_rails['smtp_ca_file'] = "/etc/ssl/certs/ca-certificates.crt" ### Email Settings # gitlab_rails['gitlab_email_enabled'] = true ##! If your SMTP server does not like the default 'From: gitlab@gitlab.example.com' ##! can change the 'From' with this setting. # gitlab_rails['gitlab_email_from'] = 'example@example.com' # gitlab_rails['gitlab_email_display_name'] = 'Example' # gitlab_rails['gitlab_email_reply_to'] = 'noreply@example.com' # gitlab_rails['gitlab_email_subject_suffix'] = '' # gitlab_rails['gitlab_email_smime_enabled'] = false # gitlab_rails['gitlab_email_smime_key_file'] = '/etc/gitlab/ssl/gitlab_smime.key' # gitlab_rails['gitlab_email_smime_cert_file'] = '/etc/gitlab/ssl/gitlab_smime.crt' # gitlab_rails['gitlab_email_smime_ca_certs_file'] = '/etc/gitlab/ssl/gitlab_smime_cas.crt' ### GitLab user privileges # gitlab_rails['gitlab_default_can_create_group'] = true # gitlab_rails['gitlab_username_changing_enabled'] = true
SES・Route53側の設定など
・Amazon SES > 設定: 検証済み ID > XXXX-dev-1.com 画面
・Route53で取得したドメインのレコード
S3に出力したSESのログでバウンスメールを確認
{ "eventType": "Bounce", "bounce": { "feedbackId": "010601870ec9f6a9-5c7ae147-2790-467a-91c1-7655c73c72da-000000", "bounceType": "Permanent", "bounceSubType": "General", "bouncedRecipients": [ { "emailAddress": "bounce@simulator.amazonses.com", "action": "failed", "status": "5.1.1", "diagnosticCode": "smtp; 550 5.1.1 user unknown" } ], "timestamp": "2023-03-23T14:05:29.780Z", "reportingMTA": "dns; e234-5.smtp-out.ap-northeast-1.amazonses.com" }, "mail": { "timestamp": "2023-03-23T14:05:28.554Z", "source": "aaa@XXXX-dev-1.com", "sourceArn": "arn:aws:ses:ap-northeast-1:5613644XXXXX:identity/XXXX-dev-1.com", "sendingAccountId": "5613644XXXXX", "messageId": "010601870ec9f26a-9cd6c090-756b-4842-ab27-17addab711d2-000000", "destination": [ "bounce@simulator.amazonses.com" ], "headersTruncated": false, "headers": [ { "name": "From", "value": "aaa@XXXX-dev-1.com" }, { "name": "To", "value": "bounce@simulator.amazonses.com" }, { "name": "Subject", "value": "111" }, { "name": "MIME-Version", "value": "1.0" }, { "name": "Content-Type", "value": "multipart/alternative; boundary=\"----=_Part_515648_665387099.1679580328558\"" } ], "commonHeaders": { "from": [ "aaa@XXXX-dev-1.com" ], "to": [ "bounce@simulator.amazonses.com" ], "messageId": "010601870ec9f26a-9cd6c090-756b-4842-ab27-17addab711d2-000000", "subject": "111" }, "tags": { "ses:operation": [ "SendEmail" ], "ses:configuration-set": [ "ses-bounce-log" ], "ses:source-ip": [ "153.137.XXX.X" ], "ses:from-domain": [ "XXXX-dev-1.com" ], "ses:caller-identity": [ "t-XXXXXXXX" ] } } } { "eventType": "Send", "mail": { "timestamp": "2023-03-23T14:05:28.554Z", "source": "aaa@XXXX-dev-1.com", "sourceArn": "arn:aws:ses:ap-northeast-1:5613644XXXXX:identity/XXXX-dev-1.com", "sendingAccountId": "5613644XXXXX", "messageId": "010601870ec9f26a-9cd6c090-756b-4842-ab27-17addab711d2-000000", "destination": [ "bounce@simulator.amazonses.com" ], "headersTruncated": false, "headers": [ { "name": "From", "value": "aaa@XXXX-dev-1.com" }, { "name": "To", "value": "bounce@simulator.amazonses.com" }, { "name": "Subject", "value": "111" }, { "name": "MIME-Version", "value": "1.0" }, { "name": "Content-Type", "value": "multipart/alternative; boundary=\"----=_Part_515648_665387099.1679580328558\"" } ], "commonHeaders": { "from": [ "aaa@XXXX-dev-1.com" ], "to": [ "bounce@simulator.amazonses.com" ], "messageId": "010601870ec9f26a-9cd6c090-756b-4842-ab27-17addab711d2-000000", "subject": "111" }, "tags": { "ses:operation": [ "SendEmail" ], "ses:configuration-set": [ "ses-bounce-log" ], "ses:source-ip": [ "153.137.XXX.X" ], "ses:from-domain": [ "XXXX-dev-1.com" ], "ses:caller-identity": [ "t-XXXXXXXX" ] } }, "send": {} }
試したこと・前提
・サンドボックス外にする申請は承認されました。
・アプリ側からの送信時、cloudWatch内のメトリクス内で送信された事は確認できています。
・こちらの続き
GitLabのログ(/var/log/gitlab/gitlab-rails/production.log)
・ユーザー登録実施(メール送信)直後のログ
Processing by MetricsController#index as HTML Completed 200 OK in 51ms (Views: 0.5ms | ActiveRecord: 0.0ms | Elasticsearch: 0.0ms | Allocations: 647) Started POST "/users" for 153.137.217.8 at 2023-03-18 13:08:00 +0000 Processing by RegistrationsController#create as HTML Parameters: {"authenticity_token"=>"[FILTERED]", "new_user"=>{"first_name"=>"test First name", "last_name"=>"test Last name", "username"=>"testUsername", "email"=>"xxxxxxxx.asics+015@gmail.com", "password"=>"[FILTERED]"}} Potential spam detected for IP 153.137.217.8. Invisible Captcha timestamp not found in session. Redirected to http://xxxx-dev-1.com:8082/users/sign_in#login-pane Completed 302 Found in 1845ms (ActiveRecord: 260.6ms | Elasticsearch: 0.0ms | Allocations: 140025) Started GET "/users/sign_in" for 153.137.217.8 at 2023-03-18 13:08:02 +0000 Rendered layout layouts/mailer.html.haml (Duration: 6.3ms | Allocations: 1171) Rendered layout layouts/mailer.text.erb (Duration: 2.1ms | Allocations: 499) Processing by SessionsController#new as HTML Rendered layout layouts/devise.html.haml (Duration: 21.4ms | Allocations: 9180) Completed 200 OK in 42ms (Views: 20.3ms | ActiveRecord: 2.8ms | Elasticsearch: 0.0ms | Allocations: 15969) Delivered mail 6415b7b21aa34_1984883c646a@xxxx-dev-1.com.mail (49.2ms) Started GET "/-/metrics" for 127.0.0.1 at 2023-03-18 13:08:04 +0000 Processing by MetricsController#index as HTML Completed 200 OK in 43ms (Views: 0.5ms | ActiveRecord: 0.0ms | Elasticsearch: 0.0ms | Allocations: 647)
あなたの回答
tips
プレビュー