GitLab CE拒绝成功发送电子邮件

时间:2017-12-12 04:46:13

标签: gitlab actionmailer

我花了好几个小时仔细阅读各种Stack Overflow线程和GitLab文档,试图让GitLab中的SMTP电子邮件发送工作。不幸的是,我没有成功。

我从9.5.4 AWS市场AMI中启动了一个GitLab CE实例,然后将其升级到最新版本。帮助页面报告此版本:GitLab Community Edition 10.2.4 ba9acca。我从通过连接到VPN访问的私有EC2实例运行此GitLab实例。 GitLab实例使用SNAT实例来访问Internet。我的电子邮件域名为mydomain.com,内部GitLab域名为gitlab.corp.mydomain.com

令人困惑的是,显然有两个地方可以指定SMTP设置:/etc/gitlab/gitlab.rb/opt/gitlab/embedded/service/gitlab-rails/config/initializers/smtp_settings.rb。两个地方都存在一些设置。我已经看到过" Omnibus"使用gitlab.rb设置,而#34;源自#34;使用smtp_settings.rb;我不确定我应该使用哪些设置,所以我在两个地方都指定了设置。

相关的gitlab.rb摘录:

### Email Settings
gitlab_rails['gitlab_email_enabled'] = true
gitlab_rails['gitlab_email_from'] = 'gitlab@mydomain.com'
gitlab_rails['gitlab_email_display_name'] = 'GitLab'
gitlab_rails['gitlab_email_reply_to'] = 'noreply@mydomain.com'
gitlab_rails['gitlab_email_subject_suffix'] = ''

### GitLab email server settings
###! Docs: https://docs.gitlab.com/omnibus/settings/smtp.html
###! **Use smtp instead of sendmail/postfix.**

gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.office365.com"
gitlab_rails['smtp_port'] = 587
gitlab_rails['smtp_user_name'] = "me@mydomain.com"
gitlab_rails['smtp_password'] = "<redacted>"
gitlab_rails['smtp_domain'] = "mydomain.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = 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'

smtp_settings.rb

# To enable smtp email delivery for your GitLab instance do the following:
# 1. Rename this file to smtp_settings.rb
# 2. Edit settings inside this file
# 3. Restart GitLab instance
#
# For full list of options and their values see http://api.rubyonrails.org/classes/ActionMailer/Base.html
#
# If you change this file in a Merge Request, please also create a Merge Request on https://gitlab.com/gitlab-org/omnibus-gitlab/merge_requests

if Rails.env.production?
  Rails.application.config.action_mailer.delivery_method = :smtp

  ActionMailer::Base.delivery_method = :smtp
  ActionMailer::Base.smtp_settings = {
    address: "smtp.office365.com",
    port: 587,
    user_name: "me@mydomain.com",
    password: "<redacted>",
    domain: "mydomain.com",
    authentication: :login,
    enable_starttls_auto: true,
    openssl_verify_mode: 'none', # See ActionMailer documentation for other possible options
  }
end

使用GitLab实例中的telnet,我确认我能够在端口587上建立到smtp.office365.com的出站连接。

我找到了一个页面here,解释了如何测试电子邮件发送。执行测试后,我发现FromReply-To标头不正确,导致Office 365正确拒绝我的电子邮件,因为它来自无效的发件人:

Loading production environment (Rails 4.2.8)
irb(main):001:0> Notify.test_email('me@mydomain.com', 'Subject', 'Body').deliver_now

Notify#test_email: processed outbound mail in 120.6ms

Sent mail to me@mydomain.com (14573.5ms)
Date: Tue, 12 Dec 2017 04:42:39 +0000
From: GitLab <gitlab@gitlab.corp.mydomain.com>
Reply-To: GitLab <noreply@gitlab.corp.mydomain.com>
To: me@mydomain.com
Message-ID: <redacted>
Subject: Subject
Mime-Version: 1.0
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: 7bit
Auto-Submitted: auto-generated
X-Auto-Response-Suppress: All

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body><p>Body</p></body></html>

Net::SMTPFatalError: 550 5.7.60 SMTP; Client does not have permissions to send as this sender [CY1PR13MB0380.namprd13.prod.outlook.com]

        from /opt/gitlab/embedded/lib/ruby/2.3.0/net/smtp.rb:974:in `check_response'
        from /opt/gitlab/embedded/lib/ruby/2.3.0/net/smtp.rb:919:in `data'
        from /opt/gitlab/embedded/lib/ruby/2.3.0/net/smtp.rb:664:in `block in send_message'
        from /opt/gitlab/embedded/lib/ruby/2.3.0/net/smtp.rb:859:in `rcptto_list'
        from /opt/gitlab/embedded/lib/ruby/2.3.0/net/smtp.rb:664:in `send_message'
        from /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/mail-2.6.6/lib/mail/network/delivery_methods/smtp.rb:112:in `block in deliver!'
        from /opt/gitlab/embedded/lib/ruby/2.3.0/net/smtp.rb:522:in `start'
        from /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/mail-2.6.6/lib/mail/network/delivery_methods/smtp.rb:111:in `deliver!'
        from /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/mail-2.6.6/lib/mail/message.rb:2149:in `do_delivery'
        from /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/mail-2.6.6/lib/mail/message.rb:237:in `block in deliver'
        from /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/actionmailer-4.2.8/lib/action_mailer/base.rb:543:in `block in deliver_mail'
        from /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/activesupport-4.2.8/lib/active_support/notifications.rb:164:in `block in instrument'
        from /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/activesupport-4.2.8/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
        from /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/activesupport-4.2.8/lib/active_support/notifications.rb:164:in `instrument'
        from /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/actionmailer-4.2.8/lib/action_mailer/base.rb:541:in `deliver_mail'
        from /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/mail-2.6.6/lib/mail/message.rb:237:in `deliver'
        from /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/actionmailer-4.2.8/lib/action_mailer/message_delivery.rb:85:in `deliver_now'
        from (irb):1
        from /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/railties-4.2.8/lib/rails/commands/console.rb:110:in `start'
        from /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/railties-4.2.8/lib/rails/commands/console.rb:9:in `start'
        from /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/railties-4.2.8/lib/rails/commands/commands_tasks.rb:68:in `console'
        from /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/railties-4.2.8/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
        from /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/railties-4.2.8/lib/rails/commands.rb:17:in `<top (required)>'
        from bin/rails:9:in `require'
        from bin/rails:9:in `<main>'

我不知道那些FromReply-To地址来自哪里。它们不会出现在我的gitlab.rb配置中。我确信这就是电子邮件发送失败的原因。

问题:

  • 这里发生了什么?
  • GitLab在哪里记录此活动?
  • 为什么在两个不同的地方指定了相同的设置?

1 个答案:

答案 0 :(得分:0)

错误就像您在评论中所说的那样,您已经评论了您的设置。此外,您应该注意到,对于Omnibus安装的Gitlab,您应该使用的唯一设置是smtp_settings

此文件用于生成其他设置文件,例如sudo gitlab-ctl reconfigure。 如果运行命令glob,将执行文件的重新生成,当您升级实例时也会触发此命令。