Linux

GitLab 不發送郵件

  • October 17, 2015

我的虛擬機上安裝了 Linux Ubuntu 14.04。最近我按照GitLab網站上的說明安裝了GitLab 7.8.2 ,在製作Gitlab發送郵件時遇到了問題。

例如,當我嘗試使用 Web 界面創建新使用者時,我沒有收到來自伺服器的任何確認郵件。

  • 我已經為我的環境配置了 postfix(設置“mynetworks”、“myhostname”),並使用 sendmail 成功地將測試郵件發送到我的 yahoo 帳戶。
  • 我將此行添加到文件**/opt/gitlab/embedded/service/gitlab-ci/config/environments/production.rb**:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = { 
  address: "127.0.0.1", 
  port: 25,
  enable_starttls_auto: false 
}
  • 我在註冊到我的 GitLab 實例時跟踪了**/var/log/mail.log並設法看到 GitLab 實際上與 postfix 互動但未成功。日誌提示操作不成功,因為 ip 被阻止,但我認為這是不正確的,因為我可以使用sendmail**命令發送郵件。

/var/log/mail.log:

Mar  6 10:58:32 ubuntu postfix/qmgr[12506]: 5BEE724E74: from=<gitlab@ubuntu>, size=630, nrcpt=1 (queue active)
Mar  6 10:59:02 ubuntu postfix/smtp[19746]: connect to example.com[93.184.216.34]:25: Connection timed out
Mar  6 10:59:02 ubuntu postfix/smtp[19746]: connect to example.com[2606:2800:220:1:248:1893:25c8:1946]:25: Network is unreachable
Mar  6 10:59:02 ubuntu postfix/smtp[19746]: 5BEE724E74: to=<admin@example.com>, relay=none, delay=30, delays=0.16/0.1/30/0, dsn=4.4.1, status=deferred (connect to example.com[2606:2800:220:1:248:1893:25c8:1946]:25: Network is unreachable)
Mar  6 11:00:50 ubuntu postfix/pickup[12505]: 07BF424E7A: uid=999 from=<gitlab@ubuntu>
Mar  6 11:00:50 ubuntu postfix/cleanup[19923]: 07BF424E7A: message-id=<54f9f961dca8d_4cc8fc2c6882575@ubuntu.mail>
Mar  6 11:00:50 ubuntu postfix/qmgr[12506]: 07BF424E7A: from=<gitlab@ubuntu>, size=626, nrcpt=1 (queue active)
Mar  6 11:00:51 ubuntu postfix/smtp[19925]: 07BF424E7A: to=<matoni@yahoo.com>, relay=mta6.am0.yahoodns.net[66.196.118.33]:25, delay=1.1, delays=0.02/0.01/0.86/0.18, dsn=5.7.1, status=bounced (host mta6.am0.yahoodns.net[66.196.118.33] said: 553 5.7.1 [BL21] Connections will not be accepted from 109.65.131.14, because the ip is in Spamhaus's list; see http://postmaster.yahoo.com/550-bl23.html (in reply to MAIL FROM command))
Mar  6 11:00:51 ubuntu postfix/smtp[19925]: 07BF424E7A: lost connection with mta6.am0.yahoodns.net[66.196.118.33] while sending RCPT TO
Mar  6 11:00:51 ubuntu postfix/cleanup[19923]: 1A85F24E7C: message-id=<20150306190051.1A85F24E7C@ubuntu>
Mar  6 11:00:51 ubuntu postfix/qmgr[12506]: 1A85F24E7C: from=<>, size=2643, nrcpt=1 (queue active)
Mar  6 11:00:51 ubuntu postfix/bounce[19929]: 07BF424E7A: sender non-delivery notification: 1A85F24E7C
Mar  6 11:00:51 ubuntu postfix/qmgr[12506]: 07BF424E7A: removed

我發現了問題。正如您在日誌中看到的:

Mar  6 11:00:51 ubuntu postfix/smtp[19925]: 07BF424E7A: to=<matangivoni@yahoo.com>, relay=mta6.am0.yahoodns.net[66.196.118.33]:25, delay=1.1, delays=0.02/0.01/0.86/0.18, dsn=5.7.1, status=bounced (host mta6.am0.yahoodns.net[66.196.118.33] said: 553 5.7.1 [BL21] Connections will not be accepted from 109.65.131.14, because the ip is in Spamhaus's list; see http://postmaster.yahoo.com/550-bl23.html (in reply to MAIL FROM command))

它說錯誤是作為對 MAIL FROM 命令的回复而引發的。正如您在此日誌行中看到的:

Mar  6 11:00:50 ubuntu postfix/pickup[12505]: 07BF424E7A: uid=999 from=<gitlab@ubuntu>

我的域名是**@ubunto**,這是一個糟糕的域名!

我需要通過將 GitLab 配置文件中的“external_url”變數從“ http://ubuntu ”設置為 FQDN 來更改我的域名。( /etc/gitlab/gitlab.rb )

您來自 gitlab 實例的郵件已被您的 postfix 接受

Mar  6 10:58:32 ubuntu postfix/qmgr[12506]: 5BEE724E74: from=<gitlab@ubuntu>, size=630, nrcpt=1 (queue active)

但是運送到目的地在這裡不起作用:

Mar  6 10:59:02 ubuntu postfix/smtp[19746]: 5BEE724E74: to=<admin@example.com>, relay=none, delay=30, delays=0.16/0.1/30/0, dsn=4.4.1, status=deferred (connect to example.com[2606:2800:220:1:248:1893:25c8:1946]:25: Network is unreachable)

您的伺服器嘗試使用 IPv6,但無法連接。看來您必須手動禁用 IPv6,在您的main.cf

inet_protocols = ipv4

但是中繼(發送)到雅虎會導致錯誤:

Mar  6 11:00:51 ubuntu postfix/smtp[19925]: 07BF424E7A: to=<matangivoni@yahoo.com>, relay=mta6.am0.yahoodns.net[66.196.118.33]:25, delay=1.1, delays=0.02/0.01/0.86/0.18, dsn=5.7.1, status=bounced (host mta6.am0.yahoodns.net[66.196.118.33] said: 553 5.7.1 [BL21] Connections will not be accepted from 109.65.131.14, because the ip is in Spamhaus's list; see http://postmaster.yahoo.com/550-bl23.html (in reply to MAIL FROM command))

它被拒絕了,因為您的動態 IP 109.65.131.14 在郵件列表中。看來你家裡有這個實例,使用動態 IP。但是,當該 IP 的先前使用者之一試圖發送垃圾郵件時,這些郵件通常會出現在垃圾郵件列表中。可能需要靜態 IP(在家或在其他地方)或使用中繼伺服器。並使用正確的 FQDN,為 IP 等設置正確的反向 DNS 記錄 (PTR),查看許多其他關於如何不被歸類為垃圾郵件的問題。

由於發送過程失敗,將向發件人發送未送達通知

Mar  6 11:00:51 ubuntu postfix/bounce[19929]: 07BF424E7A: sender non-delivery notification: 1A85F24E7C
Mar  6 11:00:51 ubuntu postfix/qmgr[12506]: 07BF424E7A: removed

您可能應該閱讀返回給使用者的郵件gitlab或將其配置為管理員帳戶的別名。

引用自:https://serverfault.com/questions/673609