自建sentry后,配置了邮件服务,但是还是收不到验证邮件?

pigLoveRabbit
  • 6.6k

问题描述

我已经在config.yml中配置了邮件服务器

mail.backend: 'smtp'  # Use dummy if you want to disable email entirely
mail.host: 'smtp.exmail.qq.com'
mail.port: 587
mail.username: '×××××××'
mail.password: '×××××××'
mail.use-tls: true
# The email address to send on behalf of
mail.from: '××××××'

而且发送测试邮件,我也收到了

clipboard.png

clipboard.png

但是我在验证邮件部分,却一直收不到邮件

clipboard.png

是我什么地方还没有配置吗?
看了一下smtp service的log

 290 Connecting to gmail-smtp-in.l.google.com [2404:6800:4008:c07::1b]:25 ... failed: Cannot assign requested address
smtp_1       |   290 LOG: MAIN
smtp_1       |   290   H=gmail-smtp-in.l.google.com [2404:6800:4008:c07::1b] Cannot assign requested address
smtp_1       |   290 Connecting to gmail-smtp-in.l.google.com [108.177.97.26]:25 ... failed: Connection timed out (timeout=5m)
smtp_1       |   290 LOG: MAIN
smtp_1       |   290   H=gmail-smtp-in.l.google.com [108.177.97.26] Connection timed out
smtp_1       |   290 Connecting to alt1.gmail-smtp-in.l.google.com [2607:f8b0:4003:c19::1a]:25 ... failed: Cannot assign requested address
smtp_1       |   290 LOG: MAIN
smtp_1       |   290   H=alt1.gmail-smtp-in.l.google.com [2607:f8b0:4003:c19::1a] Cannot assign requested address
smtp_1       |   290 Connecting to alt1.gmail-smtp-in.l.google.com [209.85.235.26]:25 ... failed: Connection timed out (timeout=5m)
smtp_1       |   290 LOG: MAIN
smtp_1       |   290   H=alt1.gmail-smtp-in.l.google.com [209.85.235.26] Connection timed out
smtp_1       |   290 Connecting to alt2.gmail-smtp-in.l.google.com [2607:f8b0:4001:c1d::1b]:25 ... failed: Cannot assign requested address
smtp_1       |   290 LOG: MAIN
smtp_1       |   290   H=alt2.gmail-smtp-in.l.google.com [2607:f8b0:4001:c1d::1b] Cannot assign requested address
smtp_1       |   290 Connecting to alt3.gmail-smtp-in.l.google.com [2607:f8b0:4002:c08::1a]:25 ... failed: Cannot assign requested address
smtp_1       |   290 LOG: MAIN
smtp_1       |   290   H=alt3.gmail-smtp-in.l.google.com [2607:f8b0:4002:c08::1a] Cannot assign requested address
smtp_1       |   290 Connecting to alt4.gmail-smtp-in.l.google.com [2607:f8b0:400d:c0e::1a]:25 ... failed: Cannot assign requested address
smtp_1       |   290 LOG: MAIN
smtp_1       |   290   H=alt4.gmail-smtp-in.l.google.com [2607:f8b0:400d:c0e::1a] Cannot assign requested address
smtp_1       |   289 LOG: MAIN
smtp_1       |   289   == energy3456789@gmail.com R=dnslookup T=remote_smtp defer (99): Cannot assign requested address
回复
阅读 5k
3 个回答

其实这个问题,在docker-compose.yml添加环境变量就好了:

version: '3.4'

x-defaults: &defaults
  restart: unless-stopped
  build: .
  depends_on:
    - redis
    - postgres
    - memcached
    - smtp

  environment:
    # Run `docker-compose run web config generate-secret-key`
    # to get the SENTRY_SECRET_KEY value.
    SENTRY_SECRET_KEY: '1o-sqivmbumzrgzyx@wgn3&9l2)xvxktgr+t-o9%9d0@=de&27'
    SENTRY_MEMCACHED_HOST: memcached
    SENTRY_REDIS_HOST: redis
    SENTRY_POSTGRES_HOST: postgres
    # 这里添加一下
    SENTRY_SERVER_EMAIL: 'your_username'
    SENTRY_EMAIL_HOST: 'smtp.exmail.qq.com'
    SENTRY_EMAIL_PORT: 587
    SENTRY_EMAIL_USER: 'your_username'
    SENTRY_EMAIL_PASSWORD: '********'
    SENTRY_EMAIL_USE_TLS: 'true'
    ....
    

我发现,发送验证邮件和异常的通知邮件,都是通过worker这个Service

以下答案不是最新的,但是体现了我解决的过程

我昨天认真的看了一下日志,发现验证邮件是通过smtp这个Service发送的,然后我看了它的日志:

smtp_1       |   290 LOG: MAIN
smtp_1       |   290   H=gmail-smtp-in.l.google.com [2404:6800:4008:c07::1b] Cannot assign requested address
smtp_1       |   290 Connecting to gmail-smtp-in.l.google.com [108.177.97.26]:25 ... failed: Connection timed out (timeout=5m)
smtp_1       |   290 LOG: MAIN
smtp_1       |   290   H=gmail-smtp-in.l.google.com [108.177.97.26] Connection timed out
smtp_1       |   290 Connecting to alt1.gmail-smtp-in.l.google.com [2607:f8b0:4003:c19::1a]:25 ... failed: Cannot assign requested address

发现这个服务并没有去使用config.yml中的配置,因为我配置的smtp server是腾讯的smtp.exmail.qq.com,端口为587
我已经在web这个Service添加了挂载了

web:
    <<: *defaults
    ports:
      - '127.0.0.1:9000:9000'
    volumes:
      - ./config.yml:/etc/sentry/config.yml

web这个Service,也就是使用的web界面,是正确读取了配置了,那说明问题在于smtp这个Service。
我看了一下它的镜像,是使用tianon/exim4这个镜像,它的入口shell

#!/bin/bash
set -e

opts=(
    dc_local_interfaces '0.0.0.0 ; ::0'
    dc_other_hostnames ''
    dc_relay_nets '0.0.0.0/0'
)

if [ "$GMAIL_USER" -a "$GMAIL_PASSWORD" ]; then
    # see https://wiki.debian.org/GmailAndExim4
    opts+=(
        dc_eximconfig_configtype 'smarthost'
        dc_smarthost 'smtp.gmail.com::587'
    )
    echo "*.google.com:$GMAIL_USER:$GMAIL_PASSWORD" > /etc/exim4/passwd.client
else
    opts+=(
        dc_eximconfig_configtype 'internet'
    )
fi

set-exim4-update-conf "${opts[@]}"

if [ "$(id -u)" = '0' ]; then
    mkdir -p /var/spool/exim4 /var/log/exim4 || :
    chown -R Debian-exim:Debian-exim /var/spool/exim4 /var/log/exim4 || :
fi

exec "$@"

查询了一下,这个镜像是使用debian上的Exim4来发送邮件的,它的一些配置

dc_eximconfig_configtype='internet'
dc_other_hostnames=''
dc_local_interfaces='127.0.0.1'
dc_readhost=''
dc_relay_domains=''
dc_minimaldns='false'
dc_relay_nets=''
dc_smarthost=''
CFILEMODE='644'
dc_use_split_config='false'
dc_hide_mailname=''
dc_mailname_in_oh='true'
dc_localdelivery='maildir_home'

dc_eximconfig_configtype这个参数,写了internet的话,smtp是自动去查询出来的,所以smtp server的日志里,才会去使用google的smtp server,如果你要写固定的配置的话,你应该把dc_eximconfig_configtype协成smarthost,然后配置dc_smarthost为你的smtp server,注意里头是两个冒号,另外还需要把对应的账号密码写到/etc/exim4/passwd.client这个口令文件中,如

*.google.com:your_user_name:your_password

.google.com之前的只是一个通配,其实这些事从这段shell也看出来了

if [ "$GMAIL_USER" -a "$GMAIL_PASSWORD" ]; then
    # see https://wiki.debian.org/GmailAndExim4
    opts+=(
        dc_eximconfig_configtype 'smarthost'
        dc_smarthost 'smtp.gmail.com::587'
    )
    echo "*.google.com:$GMAIL_USER:$GMAIL_PASSWORD" > /etc/exim4/passwd.client
else

所有,我目前临时解决了一下,就是把这个docker-entrypoint.sh给改了,挂载到容器里去,记得要赋x权限,
最好的方法应该是把这个镜像改改,能识别一下环境变量

看下sentry系统监控内有没有报错

没有验证邮箱的时候也可以接收邮件通知,具体配置看这里

clipboard.png

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
你知道吗?

宣传栏