메일 수신기가 Discourse로 메일을 전달하지 않습니다

저도 같은 실수를 범해서 mail-receiver.yml 파일에 discourse.example.com을 그대로 두었습니다.

지금 수정은 완료했지만, mail-receiver가 새 정보를 가져오지 않는 것 같습니다.
mail-receiver를 '초기화’하는 방법은 무엇인가요? (예: ./launcher rebuild app 명령에 해당하는 명령은 무엇인가요?)

수정: 이전 게시물을 충분히 꼼꼼히 읽지 않았습니다. 해당 명령은 ./launcher rebuild mail_receiver입니다.

이제 mail-receiver가 Discourse로 메일을 전달하지 못하는 추가 문제가 발생했습니다. 도움을 위해 검색을 해보았지만 해결책을 찾지 못했습니다.

로그:

Starting Postfix
Dec 14 03:12:32 forum-mail-receiver postfix/master[1]: daemon started -- version 3.5.6, configuration /etc/postfix
Dec 14 03:15:47 forum-mail-receiver postfix/smtpd[113]: connect from mail-pl1-f169.google.com[209.85.214.169]
Dec 14 03:15:47 forum-mail-receiver postfix/smtpd[113]: 821CB37A659: client=mail-pl1-f169.google.com[209.85.214.169]
Dec 14 03:15:47 forum-mail-receiver postfix/cleanup[120]: 821CB37A659: message-id=<602f2194be912e92b969eacf5eac26e2@frontapp.com>
Dec 14 03:15:47 forum-mail-receiver postfix/qmgr[98]: 821CB37A659: from=<[my personal email address]>, size=4086, nrcpt=1 (queue active)
<23>Dec 14 03:15:47 receive-mail[122]: Recipient: nobody@[my forum URL]Dec 14 03:16:20 forum-mail-receiver postfix/smtpd[113]: disconnect from mail-pl1-f169.google.com[209.85.214.169] ehlo=1 mail=1 rcpt=1 bdat=1 quit=1 commands=5
<19>Dec 14 03:16:47 receive-mail[122]: Failed to POST the e-mail to [my forum URL]/admin/email/handle_mail: execution expired (Net::OpenTimeout)<19>Dec 14 03:16:47 receive-mail[122]:   /usr/lib/ruby/2.7.0/net/http.rb:960:in `initialize'
  /usr/lib/ruby/2.7.0/net/http.rb:960:in `open'
  /usr/lib/ruby/2.7.0/net/http.rb:960:in `block in connect'
  /usr/lib/ruby/2.7.0/timeout.rb:105:in `timeout'
  /usr/lib/ruby/2.7.0/net/http.rb:958:in `connect'
  /usr/lib/ruby/2.7.0/net/http.rb:943:in `do_start'
  /usr/lib/ruby/2.7.0/net/http.rb:932:in `start'
  /usr/lib/ruby/2.7.0/net/http.rb:1483:in `request'
  /usr/local/lib/site_ruby/mail_receiver/discourse_mail_receiver.rb:43:in `process'
  /usr/local/bin/receive-mail:13:in `<main>'Dec 14 03:16:47 forum-mail-receiver postfix/pipe[121]: 821CB37A659: to=<nobody@[my forum URL]>, relay=discourse, delay=60, delays=0.17/0.01/0/60, dsn=4.3.0, status=deferred (temporary failure)
Dec 14 03:17:32 forum-mail-receiver postfix/qmgr[98]: 7C67437A663: from=<[my personal email address]>, size=4093, nrcpt=1 (queue active)

이것이 발생하는 원인이 무엇일지 혹시 아는 분이 있을까요?

mail-receiver.yml 파일은 유효하며 오타가 없는지 확인했습니다:

제 API 키 범위는 다음과 같습니다:

메일은 mail-receiver에 도달하지만, mailq에 그대로 쌓여 있습니다:

또는, mail-receiver 컨테이너를 완전히 삭제하고 처음부터 다시 시작하는 방법이 있을까요?

문제는 API 키가 설정되어 있지 않은 것일 수 있습니다.

@pfaffman 님, 답변 주셔서 감사합니다… mail-receiver.yml 설정 파일에는 확실히 설정되어 있습니다. 따옴표로 묶어야 하나요?

 (Net::OpenTimeout)

이것이 문제입니다. 메일 수신기가 포럼 URL에 접근할 수 없습니다. 따라서 URL이 잘못 설정되었거나, Docker 내에서 메일 수신기와 포럼 사이에 네트워크 문제가 있는 것 같습니다.

더 이상의 문제를 해결하려면 어떻게 해야 하나요?

ping forum.[mydomain].co.nz

명령을 mailq 내부에서 실행하면 다음과 같은 결과가 표시됩니다:

64 bytes from [ip].vultrusercontent.com ([ip]): icmp_seq=1 ttl=64 time=0.113 ms
64 bytes from [ip].vultrusercontent.com ([ip]): icmp_seq=2 ttl=64 time=0.074 ms
64 bytes from [ip].vultrusercontent.com ([ip]): icmp_seq=3 ttl=64 time=0.069 ms

이와 유사한 결과들이 계속 표시되며, 연결이 성공적으로 이루어지고 있음을 보여줍니다.
forum.[mydomain].co.nz는 포럼이 호스팅되는 주소이며, 이 동일한 URL이 MAIL_DOMAIN과 DISCOURSE_MAIL_ENDPOINT 설정에 사용됩니다.

mail-receiver.yml 설정을 자세히 살펴보니, 따옴표나 https:// 프로토콜이 필요한 곳에 누락된 부분이 있을까요?

## this is the incoming mail receiver container template
##
## After making changes to this file, you MUST rebuild
## /var/discourse/launcher rebuild mail-receiver
##
## BE *VERY* CAREFUL WHEN EDITING!
## YAML FILES ARE SUPER SUPER SENSITIVE TO MISTAKES IN WHITESPACE OR ALIGNMENT!
## visit http://www.yamllint.com/ to validate this file as needed

base_image: discourse/mail-receiver:release
update_pups: false

expose:
  - "25:25"   # SMTP

env:
  LC_ALL: en_US.UTF-8
  LANG: en_US.UTF-8
  LANGUAGE: en_US.UTF-8

  ## Where e-mail to your forum should be sent.  In general, it's perfectly fine
  ## to use the same domain as the forum itself here.
  MAIL_DOMAIN: forum.[domain].co.nz
# uncomment these (and the volume below!) to support TLS
#  POSTCONF_smtpd_tls_key_file:  /letsencrypt/discourse.example.com/discourse.example.com.key
#  POSTCONF_smtpd_tls_cert_file:  /letsencrypt/discourse.example.com/fullchain.cer
#  POSTCONF_smtpd_tls_security_level: may


  ## The URL of the mail processing endpoint of your Discourse forum.
  ## This is simply your forum's base URL, with `/admin/email/handle_mail`
  ## appended.  Be careful if you're running a subfolder setup -- in that case,
  ## the URL needs to have the subfolder included!
  DISCOURSE_MAIL_ENDPOINT: 'https://forum.[domain].co.nz/admin/email/handle_mail'

  ## The master API key of your Discourse forum.  You can get this from
  ## the "API" tab of your admin panel.
  DISCOURSE_API_KEY: 639[rest of API key]884ef

  ## The username to use for processing incoming e-mail.  Unless you have
  ## renamed the `system` user, you should leave this as-is.
  DISCOURSE_API_USERNAME: system

volumes:
  - volume:
      host: /var/discourse/shared/mail-receiver/postfix-spool
      guest: /var/spool/postfix
# uncomment to support TLS
#  - volume:
#      host: /var/discourse/shared/standalone/letsencrypt
#      guest: /letsencrypt

컨테이너 안에서, 즉 먼저 ./launcher enter mail-receiver를 실행한 후에 ping을 실행하고 계신가요?

ping(일반적으로 ICMP)은 http/https 연결(TCP)과 다르며, 네트워크 구성의 여러 요인에 따라 동작 방식이 다를 수 있다는 점도 참고하세요.

컨테이너에 진입한 후 curl을 사용하여 포럼에 https로 연결할 수 있는지 확인해 보시는 것을 권장합니다. 예를 들어 다음과 같이 실행해 보세요.

cd /var/discourse
./launcher enter mail-receiver
curl -v https://forum.[domain].co.nz

정상적으로 작동하면 HTML이 대량으로 출력됩니다. 작동하지 않으면 오류가 표시되며, -v 옵션을 사용하면 중간 과정에 대한 많은 양의 정보가 출력되어 실패 원인을 파악하는 데 도움이 될 수 있습니다.

실패하는 경우, 컨테이너 밖에서 동일한 curl 명령을 실행해 보시는 것도 좋습니다. 이를 통해 문제가 컨테이너에만 국한된 것인지, 아니면 호스트 시스템 전체에 해당하는 것인지 확인할 수 있습니다.

@Simon_Manning님, 도움 주셔서 정말 감사합니다! ping을 통한 연결과 curl을 통한 연결이 반드시 동일하지 않을 수 있다는 사실은 몰랐습니다.

컨테이너 안에서 ping을 실행했는데 성공했습니다.

말씀하신 대로 컨테이너 안에서 curl을 실행해 보니 실패했습니다:

root@forum:/var/discourse# ./launcher enter mail-receiver
x86_64 arch detected.
WARNING: containers/mail-receiver.yml file is world-readable. You can secure this file by running: chmod o-rwx containers/mail-receiver.yml
bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
root@forum-mail-receiver:/# curl -v https://forum.[domain].co.nz
*   Trying [IPv4 address]:443...
*   Trying [IPv6 address]:443...
* Immediate connect fail for [IPv6 address]: Cannot assign requested address
* connect to [IPv4 address] port 443 failed: Connection timed out
* Failed to connect to forum.[domain].co.nz port 443: Connection timed out
* Closing connection 0
curl: (28) Failed to connect to forum.[domain].co.nz port 443: Connection timed out

그다음 exit를 실행하고 다시 curl을 실행해 보니 다음과 같은 결과가 나왔습니다:

root@forum:/var/discourse# curl -v https://forum.[domain].co.nz
*   Trying 127.0.1.1:443...
* Connected to forum.[domain].co.nz (127.0.1.1) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
*  CAfile: /etc/ssl/certs/ca-certificates.crt
*  CApath: /etc/ssl/certs
* TLSv1.0 (OUT), TLS header, Certificate Status (22):
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS header, Certificate Status (22):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
...and so on.

호스트 시스템이 아니라 컨테이너에 특이한 문제인 것 같습니다. 혹시 아이디어가 있으신가요?

또한 이 인스턴스의 VPS 제공업체인 Vultr에 지원 티켓을 제출하여 상대방 측에 문제가 있는지 확인해 달라고 요청했습니다!

Docker는 컨테이너를 위해 가상 네트워크를 생성하며, 네트워크를 명시적으로 지정하지 않으면 컨테이너는 기본 네트워크를 사용합니다. 이 기본 네트워크에서는 컨테이너 간 통신이 허용되지 않습니다.

보통 메일 리시버(mail-receiver)의 경우 이는 문제가 되지 않습니다. Discourse 컨테이너가 해당 네트워크 외부로 443 포트가 노출되어 있기 때문입니다. 메일 리시버가 1.2.3.4로 연결을 시도하면 Docker 네트워크를 벗어나게 됩니다. 호스트 시스템(또는 더 외부의 네트워크 장비)은 다시 원래 경로로 돌아와야 함을 인식하고, 결국 외부에서 Discourse 컨테이너로 진입하게 됩니다.

두 가지 가능성이 떠오릅니다. 하나는 메일 리시버가 도메인 이름을 조회할 때 Discourse 컨테이너의 IP를 알아차리고, 이로 인해 컨테이너 내부 연결이 차단되는 경우입니다. 저는 이 가능성은 낮다고 봅니다.

다른 하나는 호스트 시스템의 방화벽이 컨테이너에서 나가는 연결과 다른 컨테이너로 들어오는 연결을 차단하고 있는 경우입니다. Vultr가 이를 유발할 수 있는 기본 방화벽 규칙을 사용할 수 있으며, Docker가 기본적으로 UFW에 일부 규칙을 설치한다는 것도 희미하게 기억나므로, UFW를 사용하고 있다면 이 문제와 관련이 있을 수 있습니다.

아래의 주석을 해제하지 않았기 때문에 https를 사용할 수 없습니다:

이것은 메일 서버 측의 TLS 지원, 즉 다른 메일 서버가 TLS를 통해 mail-receiver에 이메일을 전달할 수 있도록 하는 것과 관련이 있습니다.

Discourse 컨테이너에는 분명히 인증서가 있으므로 이를 실행하는 것이 가치가 있지만, mail-receiver가 Discourse에 연결하는 데에는 영향을 주지 않아야 합니다. 다만 컨테이너의 네트워크 설정에서 무언가를 수정하게 된다면 재구축이 영향을 줄 수도 있습니다.

감사합니다. 해당 줄들과 볼륨 관련 줄의 주석을 해제했습니다.

현재 제 mail-receiver.yml 파일은 다음과 같습니다:

root@forum:/var/discourse# cat containers/mail-receiver.yml
## this is the incoming mail receiver container template
##
## After making changes to this file, you MUST rebuild
## /var/discourse/launcher rebuild mail-receiver
##
## BE *VERY* CAREFUL WHEN EDITING!
## YAML FILES ARE SUPER SUPER SENSITIVE TO MISTAKES IN WHITESPACE OR ALIGNMENT!
## visit http://www.yamllint.com/ to validate this file as needed

base_image: discourse/mail-receiver:release
update_pups: false

expose:
  - "25:25"   # SMTP

env:
  LC_ALL: en_US.UTF-8
  LANG: en_US.UTF-8
  LANGUAGE: en_US.UTF-8

  ## Where e-mail to your forum should be sent.  In general, it's perfectly fine
  ## to use the same domain as the forum itself here.
  MAIL_DOMAIN: forum.[domain].co.nz
# uncomment these (and the volume below!) to support TLS
  POSTCONF_smtpd_tls_key_file:  /letsencrypt/forum.[domain].co.nz/forum.[domain].co.nz.key
  POSTCONF_smtpd_tls_cert_file:  /letsencrypt/forum.[domain].co.nz/fullchain.cer
  POSTCONF_smtpd_tls_security_level: may


  ## The URL of the mail processing endpoint of your Discourse forum.
  ## This is simply your forum's base URL, with `/admin/email/handle_mail`
  ## appended.  Be careful if you're running a subfolder setup -- in that case,
  ## the URL needs to have the subfolder included!
  DISCOURSE_MAIL_ENDPOINT: 'https://forum.[domain].co.nz/admin/email/handle_mail'

  ## The master API key of your Discourse forum.  You can get this from
  ## the "API" tab of your admin panel.
  DISCOURSE_API_KEY: '074[rest of API key - yes I generated a new one limited to the system user]d98'

  ## The username to use for processing incoming e-mail.  Unless you have
  ## renamed the `system` user, you should leave this as-is.
  DISCOURSE_API_USERNAME: system

volumes:
  - volume:
      host: /var/discourse/shared/mail-receiver/postfix-spool
      guest: /var/spool/postfix
# uncomment to support TLS
  - volume:
      host: /var/discourse/shared/standalone/letsencrypt
      guest: /letsencrypt

새로운 이메일을 보내고 ./launcher logs mail-receiver를 실행하면 다음과 같은 내용이 표시됩니다:

Dec 21 22:41:21 forum-mail-receiver postfix/smtpd[132]: connect from mail-pj1-f54.google.com[209.85.216.54]
Dec 21 22:41:23 forum-mail-receiver postfix/smtpd[132]: 16DAC379E42: client=mail-pj1-f54.google.com[209.85.216.54]
Dec 21 22:41:23 forum-mail-receiver postfix/cleanup[139]: 16DAC379E42: message-id=<94fc2bef18b410ae8b121c6af2da2df4@frontapp.com>
Dec 21 22:41:23 forum-mail-receiver postfix/qmgr[100]: 16DAC379E42: from=<[my email address]>, size=5585, nrcpt=1 (queue active)
<23>Dec 21 22:41:23 receive-mail[141]: Recipient: nobody@forum.[domain].co.nzDec 21 22:41:50 forum-mail-receiver postfix/smtpd[143]: connect from mail-oa1-f50.google.com[209.85.160.50]
Dec 21 22:41:52 forum-mail-receiver postfix/smtpd[143]: 2E445379E48: client=mail-oa1-f50.google.com[209.85.160.50]
Dec 21 22:41:52 forum-mail-receiver postfix/cleanup[139]: 2E445379E48: message-id=<6b2f9d646dc46f4fec4af006de01d3ae@frontapp.com>
Dec 21 22:41:52 forum-mail-receiver postfix/qmgr[100]: 2E445379E48: from=<[my email address]>, size=4100, nrcpt=1 (queue active)
<23>Dec 21 22:41:52 receive-mail[147]: Recipient: nobody@forum.[domain].co.nzDec 21 22:41:53 forum-mail-receiver postfix/smtpd[132]: disconnect from mail-pj1-f54.google.com[209.85.216.54] ehlo=2 starttls=1 mail=1 rcpt=1 bdat=1 quit=1 commands=7
Dec 21 22:41:58 forum-mail-receiver postfix/qmgr[100]: 1194937A670: from=<double-bounce@forum-mail-receiver.localdomain>, size=942, nrcpt=1 (queue active)
Dec 21 22:41:58 forum-mail-receiver postfix/smtp[149]: fatal: unknown service: smtp/tcp
Dec 21 22:41:59 forum-mail-receiver postfix/qmgr[100]: warning: private/smtp socket: malformed response
Dec 21 22:41:59 forum-mail-receiver postfix/qmgr[100]: warning: transport smtp failure -- see a previous warning/fatal/panic logfile record for the problem description
Dec 21 22:41:59 forum-mail-receiver postfix/master[1]: warning: process /usr/lib/postfix/sbin/smtp pid 149 exit status 1
Dec 21 22:41:59 forum-mail-receiver postfix/master[1]: warning: /usr/lib/postfix/sbin/smtp: bad command startup -- throttling
Dec 21 22:41:59 forum-mail-receiver postfix/error[150]: 1194937A670: to=<postmaster@forum-mail-receiver.localdomain>, orig_to=<postmaster>, relay=none, delay=1192, delays=1191/1/0/0.01, dsn=4.3.0, status=deferred (unknown mail transport error)
<19>Dec 21 22:42:23 receive-mail[141]: Failed to POST the e-mail to https://forum.sobercheck.co.nz/admin/email/handle_mail: execution expired (Net::OpenTimeout)<19>Dec 21 22:42:23 receive-mail[141]:   /usr/lib/ruby/2.7.0/net/http.rb:960:in `initialize'
  /usr/lib/ruby/2.7.0/net/http.rb:960:in `open'
  /usr/lib/ruby/2.7.0/net/http.rb:960:in `block in connect'
  /usr/lib/ruby/2.7.0/timeout.rb:105:in `timeout'
  /usr/lib/ruby/2.7.0/net/http.rb:958:in `connect'
  /usr/lib/ruby/2.7.0/net/http.rb:943:in `do_start'
  /usr/lib/ruby/2.7.0/net/http.rb:932:in `start'
  /usr/lib/ruby/2.7.0/net/http.rb:1483:in `request'
  /usr/local/lib/site_ruby/mail_receiver/discourse_mail_receiver.rb:43:in `process'
  /usr/local/bin/receive-mail:13:in `<main>'Dec 21 22:42:23 forum-mail-receiver postfix/pipe[140]: 16DAC379E42: to=<nobody@forum.[domain].co.nz>, relay=discourse, delay=60, delays=0.23/0.01/0/60, dsn=4.3.0, status=deferred (temporary failure)
Dec 21 22:42:25 forum-mail-receiver postfix/smtpd[143]: disconnect from mail-oa1-f50.google.com[209.85.160.50] ehlo=2 starttls=1 mail=1 rcpt=1 bdat=1 quit=1 commands=7
<19>Dec 21 22:42:52 receive-mail[147]: Failed to POST the e-mail to https://forum.[domain].co.nz/admin/email/handle_mail: execution expired (Net::OpenTimeout)<19>Dec 21 22:42:52 receive-mail[147]:   /usr/lib/ruby/2.7.0/net/http.rb:960:in `initialize'
  /usr/lib/ruby/2.7.0/net/http.rb:960:in `open'
  /usr/lib/ruby/2.7.0/net/http.rb:960:in `block in connect'
  /usr/lib/ruby/2.7.0/timeout.rb:105:in `timeout'
  /usr/lib/ruby/2.7.0/net/http.rb:958:in `connect'
  /usr/lib/ruby/2.7.0/net/http.rb:943:in `do_start'
  /usr/lib/ruby/2.7.0/net/http.rb:932:in `start'
  /usr/lib/ruby/2.7.0/net/http.rb:1483:in `request'
  /usr/local/lib/site_ruby/mail_receiver/discourse_mail_receiver.rb:43:in `process'
  /usr/local/bin/receive-mail:13:in `<main>'Dec 21 22:42:52 forum-mail-receiver postfix/pipe[146]: 2E445379E48: to=<nobody@forum.[domain].co.nz>, relay=discourse, delay=60, delays=0.15/0.01/0/60, dsn=4.3.0, status=deferred (temporary failure)
Dec 21 22:45:45 forum-mail-receiver postfix/anvil[135]: statistics: max connection rate 1/60s for (smtp:209.85.216.54) at Dec 21 22:41:21
Dec 21 22:45:45 forum-mail-receiver postfix/anvil[135]: statistics: max connection count 1 for (smtp:209.85.216.54) at Dec 21 22:41:21
Dec 21 22:45:45 forum-mail-receiver postfix/anvil[135]: statistics: max cache size 2 at Dec 21 22:41:50

지금은 정말 막막합니다. 이 문제를 일으키는 원인이 무엇일지 아이디어가 있으신 분 계신가요? :grinning_face_with_smiling_eyes:

아, 맞다. TLS와 https를 혼동했군요.

여전히 전혀 작동하지 않고, mail-receiver에서 Discourse로 이메일이 전달되지 않습니다.

mail-receiver를 처음 상태로 되돌려(전체 리셋) 다시 시도하면 작동할 수 있을까요?
이것을 어떻게 수행할 수 있을까요?

파일을 수정한 후 메일 컨테이너를 다시 빌드하면 됩니다.

방화벽에 대한 팁 감사합니다! @MathiasFoster와 비슷한 문제를 겪었습니다. app 컨테이너 내의 포럼 사이트까지 mail-receiver 컨테이너가 도달하지 못하는 상황이었습니다. 처음에는 다소 당황스러웠는데, 컨테이너가 외부 세계로 리스닝하는 데에는 아무 문제가 없었기 때문입니다.

저 역시 Vultr를 VPS 프로바이더로 사용하며, 그들의 Ubuntu OS 이미지를 사용하고 있습니다. OS 이미지의 기본 설정과 Docker의 어떤 조합이 컨테이너 간 통신을 차단하는 것 같습니다.

어쨌든 제 경우, 호스트에서 HTTPS를 허용하는 것만으로도 충분했습니다:

$ ufw allow https

그 후 mail-receiver는 예상대로 메일을 전달할 수 있었습니다.