Mailer GitLab 发送邮件失效,使用 ActionMailer 和 postfix

liujinxia · 2016年09月21日 · 最后由 liujinxia 回复于 2016年09月22日 · 11140 次阅读

求支招,自己的私有 gitlab 服务器,配置了 ActionMailer,用 smtp 来发送通知邮件。配置如下:

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

  ActionMailer::Base.smtp_settings = {
    address: "smtp.163.com",
    port: 25,
    user_name: "*****************",
    password: "**************",
    domain: "163.com",
    authentication: :login,
    enable_starttls_auto: false,
    openssl_verify_mode: 'none' # See ActionMailer documentation for other possible options
  }
end

用的是 163 邮箱服务器,向其他用户发送通知邮件。

前段时间是可以正常发送通知邮件的,这几天不知什么原因,收不到邮件了,检查 sidekiq 的日志如下:

Sidekiq::Extensions::DelayedMailer JID-b694bbc959b6972dec24430c INFO: start
2016-09-21T00:11:42.086Z 30161 TID-ouhh3htik Sidekiq::Extensions::DelayedMailer JID-b694bbc959b6972dec24430c INFO: fail: 30.018 sec
2016-09-21T00:11:42.087Z 30161 TID-ouhh3htik WARN: {"retry"=>true, "queue"=>"default", "class"=>"Sidekiq::Extensions::DelayedMailer", "args"=>["---\n- !ruby/class 'Notify'\n- :new_ssh_key_email\n- - 874\n"], "jid"=>"b694bbc959b6972dec24430c", "enqueued_at"=>1474169870.4743142, "error_message"=>"execution expired", "error_class"=>"Net::OpenTimeout", "failed_at"=>1474169908.4454546, "retry_count"=>17, "retried_at"=>1474416702.0864198}
2016-09-21T00:11:42.087Z 30161 TID-ouhh3htik WARN: execution expired
2016-09-21T00:11:42.087Z 30161 TID-ouhh3htik WARN: /usr/local/lib/ruby/2.1.0/net/smtp.rb:541:in `initialize'
/usr/local/lib/ruby/2.1.0/net/smtp.rb:541:in `open'
/usr/local/lib/ruby/2.1.0/net/smtp.rb:541:in `tcp_socket'
/usr/local/lib/ruby/2.1.0/net/smtp.rb:551:in `block in do_start'
/usr/local/lib/ruby/2.1.0/timeout.rb:91:in `block in timeout'
/usr/local/lib/ruby/2.1.0/timeout.rb:101:in `call'
/usr/local/lib/ruby/2.1.0/timeout.rb:101:in `timeout'
/usr/local/lib/ruby/2.1.0/net/smtp.rb:550:in `do_start'
/usr/local/lib/ruby/2.1.0/net/smtp.rb:520:in `start'
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/mail-2.6.4/lib/mail/network/delivery_methods/smtp.rb:113:in `deliver!'
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/mail-2.6.4/lib/mail/message.rb:2149:in `do_delivery'
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/mail-2.6.4/lib/mail/message.rb:237:in `block in deliver'
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/actionmailer-4.1.14.1/lib/action_mailer/base.rb:527:in `block in deliver_mail'
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.14.1/lib/active_support/notifications.rb:159:in `block in instrument'
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.14.1/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.14.1/lib/active_support/notifications.rb:159:in `instrument'
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/actionmailer-4.1.14.1/lib/action_mailer/base.rb:525:in `deliver_mail'
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/mail-2.6.4/lib/mail/message.rb:237:in `deliver'
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/sidekiq-3.3.0/lib/sidekiq/extensions/action_mailer.rb:32:in `deliver'
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/sidekiq-3.3.0/lib/sidekiq/extensions/action_mailer.rb:20:in `perform'
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/sidekiq-3.3.0/lib/sidekiq/processor.rb:75:in `execute_job'
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/sidekiq-3.3.0/lib/sidekiq/processor.rb:52:in `block (2 levels) in process'
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/sidekiq-3.3.0/lib/sidekiq/middleware/chain.rb:127:in `call'
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/sidekiq-3.3.0/lib/sidekiq/middleware/chain.rb:127:in `block in invoke'
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/sidetiq-0.6.3/lib/sidetiq/middleware/history.rb:8:in `call'
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/sidekiq-3.3.0/lib/sidekiq/middleware/chain.rb:129:in `block in invoke'
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/sidekiq-3.3.0/lib/sidekiq/middleware/server/active_record.rb:6:in `call'
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/sidekiq-3.3.0/lib/sidekiq/middleware/chain.rb:129:in `block in invoke'
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/sidekiq-3.3.0/lib/sidekiq/middleware/server/retry_jobs.rb:74:in `call'
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/sidekiq-3.3.0/lib/sidekiq/middleware/chain.rb:129:in `block in invoke'
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/sidekiq-3.3.0/lib/sidekiq/middleware/server/logging.rb:11:in `block in call'
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/sidekiq-3.3.0/lib/sidekiq/logging.rb:22:in `with_context'
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/sidekiq-3.3.0/lib/sidekiq/middleware/server/logging.rb:7:in `call'
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/sidekiq-3.3.0/lib/sidekiq/middleware/chain.rb:129:in `block in invoke'
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/sidekiq-3.3.0/lib/sidekiq/middleware/chain.rb:132:in `call'
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/sidekiq-3.3.0/lib/sidekiq/middleware/chain.rb:132:in `invoke'
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/sidekiq-3.3.0/lib/sidekiq/processor.rb:51:in `block in process'
"sidekiq.log" [readonly] 11741L, 1309001C                  

我不太了解 163 邮箱服务器,postfix 和目标邮箱服务器之间是怎么交互的,google 了一下 尝试在服务器上上用命令: telnat smtp.163.com 25 来连接 163 的邮箱服务器,结果一直连不上

telnet smtp.163.com 25
Trying 220.181.12.14...
Trying 220.181.12.15...
Trying 220.181.12.16...

不知道跟这个有没有关系,目前这个问题还没有解决,求助同志们🙋

你在 action_mailer 里这样设置,就直接连接 163 的 SMTP 不会走 postfix 了,当你自架邮件发送服务的时候,才需要 postfix 至于连不通 看看 163 帮助里怎么说的吧,一些服务商会加限额或者节流阀的

我也像 lz 一样用 163,也遇到过之前邮件发送正常,突然就不行了的情况

于是我换了一个邮件服务商

可能是 163 邮箱的安全策略变了,登录之后进去看看设置之类有无变化呢。我记得 gmail 是需要自降安全等级设置的。

@jasi 原来不会走 postfix 了,虽然不确切的知道为什么,但是给我排查问题带来很大的帮助,谢谢😊 。 目前找到的问题是跟网络有关的,好多外网地址 ping 不通。

需要 登录 后方可回复, 如果你还没有账号请 注册新账号