# Настройка прямой доставки входящей почты и новых тем по электронной почте

**URL:** <https://meta.discourse.org/t/trying-to-setup-direct-delivery-of-incoming-email-and-new-topic-by-email/310674>\
**Category:** Self-hosting\
**Tags:** mail-receiver\
**Created:** [05.Июнь.2024 15:02:48 UTC](https://meta.discourse.org/t/trying-to-setup-direct-delivery-of-incoming-email-and-new-topic-by-email/310674 "2024-06-05T15:02:48Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![M\_Cheseldm](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/m_cheseldm/32/390102_2.png) [@M\_Cheseldm](https://meta.discourse.org/u/M_Cheseldm)\
**Post date:** [05.Июнь.2024 15:02:48 UTC](https://meta.discourse.org/t/trying-to-setup-direct-delivery-of-incoming-email-and-new-topic-by-email/310674/1 "2024-06-05T15:02:48Z")

</div>

Я пытаюсь настроить ответ по электронной почте и создание нового поста по почте. Буду очень признателен за любую помощь.

Я настроил контейнер mail-receiver и успешно выполнил начальный запуск без ошибок на своем собственном хостинге форума Discourse, используя эти руководства:

[https://meta.discourse.org/t/configure-direct-delivery-incoming-email-for-self-hosted-sites-with-mail-receiver/49487](https://meta.discourse.org/t/configure-direct-delivery-incoming-email-for-self-hosted-sites-with-mail-receiver/49487)

[https://meta.discourse.org/t/configure-incoming-email-to-create-new-topics-or-group-messages/62977](https://meta.discourse.org/t/configure-incoming-email-to-create-new-topics-or-group-messages/62977)

Я получаю письма на свой домен, но, похоже, мои письма отклоняются из-за API-ключа.

Я использовал это руководство для настройки API-ключа: [Where do I put the variables for mail-receiver? - #4 by Simon\_Manning](https://meta.discourse.org/t/where-do-i-put-the-variables-for-mail-receiver/283803/4)

Я настроил API-ключ для системной области с целью получения писем и следующие значения по умолчанию:

- `/admin/email/smtp_should_reject (GET)`
- `/admin/email/handle_mail (POST)`

Вот пример содержимого моего лога mail-receiver:

```plaintext
 mail-qt1-f182.google.com[209.85.160.182]
<19>Jun 3 12:22:56 discourse-smtp-fast-rejection[114]: Failed to GET smtp_should_reject answer from thetarotclub.xyz/admin/email/smtp_should_reject.json: undefined method `request_uri' for #<URI::Generic:0x00005a643e1ea198> (NoMethodError)<19>Jun 3 12:22:56 discourse-smtp-fast-rejection[114]: /usr/local/lib/site_ruby/mail_receiver/fast_rejection.rb:78:in `maybe_reject_email'
  /usr/local/lib/site_ruby/mail_receiver/fast_rejection.rb:142:in `maybe_reject_by_api'
  /usr/local/lib/site_ruby/mail_receiver/fast_rejection.rb:116:in `block in run_filters'
  /usr/local/lib/site_ruby/mail_receiver/fast_rejection.rb:115:in `each'
  /usr/local/lib/site_ruby/mail_receiver/fast_rejection.rb:115:in `run_filters'
  /usr/local/lib/site_ruby/mail_receiver/fast_rejection.rb:60:in `process_single_request'
  /usr/local/lib/site_ruby/mail_receiver/fast_rejection.rb:34:in `process'
  /usr/local/bin/discourse-smtp-fast-rejection:10:in `<main>'Jun 03 12:22:56 ubuntu-2gb-ash-1-mail-receiver postfix/smtpd[108]: NOQUEUE: reject: RCPT from mail-qt1-f182.google.com[209.85.160.182]: 450 4.7.1 <replies+772ea5167ee1fabce20db67cd141a364@thetarotclub.xyz>: Recipient address rejected: Internal error, API request preparation failed; from=<cheseldm@gmail.com> to=<replies+772ea5167ee1fabce20db67cd141a364@thetarotclub.xyz> proto=ESMTP helo=<mail-qt1-f182.google.com>
Jun 03 12:22:56 ubuntu-2gb-ash-1-mail-receiver postfix/smtpd[108]: disconnect from mail-qt1-f182.google.com[209.85.160.182] ehlo=1 mail=1 rcpt=0/1 bdat=0/1 quit=1 commands=3/5
Jun 03 12:26:16 ubuntu-2gb-ash-1-mail-receiver postfix/anvil[111]: statistics: max connection rate 1/60s for (smtp:209.85.160.182) at Jun 3 12:22:56
Jun 03 12:26:16 ubuntu-2gb-ash-1-mail-receiver postfix/anvil[111]: statistics: max connection count 1 for (smtp:209.85.160.182) at Jun 3 12:22:56
Jun 03 12:26:16 ubuntu-2gb-ash-1-mail-receiver postfix/anvil[111]: statistics: max cache size 1 at Jun 3 12:22:56
Jun 03 12:43:23 ubuntu-2gb-ash-1-mail-receiver postfix/smtpd[127]: connect from mail-qt1-f176.google.com[209.85.160.176]

```

Также в конце лога mail-receiver отображается:

```plaintext
Operating environment:
HOSTNAME=ubuntu-2gb-ash-1-mail-receiver
LANGUAGE=en_US.UTF-8
MAIL_DOMAIN=thetarotclub.xyz
DOCKER_HOST_IP=172.17.0.1
PWD=/
DISCOURSE_BASE_URL=thetarotclub.xyz
HOME=/root
LANG=en_US.UTF-8
TERM=xterm
SHLVL=1
DISCOURSE_API_USERNAME=system
LC_ALL=en_US.UTF-8
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
DISCOURSE_API_KEY=
_=/usr/bin/env
Delivering mail sent to thetarotclub.xyz to Discourse
postfix/postfix-script: warning: symlink leaves directory: /etc/postfix/./makedefs.out
Jun 03 21:34:36 ubuntu-2gb-ash-1-mail-receiver postfix/postfix-script[85]: warning: symlink leaves directory: /etc/postfix/./makedefs.out
Starting Postfix
Jun 03 21:34:36 ubuntu-2gb-ash-1-mail-receiver postfix/master[1]: daemon started -- version 3.5.6, configuration /etc/postfix

```

API-ключ Discourse не совпадает с тем, который я настроил в файле /var/discourse/containers/mail-receiver.yml.

Вот мой файл mail-receiver.yml:

```plaintext
## 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: thetarotclub.xyz
# 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 base URL for this Discourse instance.
  ## This will be whatever your Discourse site URL is. For example,
  ## https://discourse.example.com. If you're running a subfolder setup,
  ## be sure to account for that (ie https://example.com/forum).
  DISCOURSE_BASE_URL: 'https://thetarotclub.xyz'

  ## The master API key of your Discourse forum. You can get this from
  ## the "API" tab of your admin panel.
 DISCOURSE_API_KEY: 
  ## 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

```

Вот ошибка, которую я получаю при отклонении писем:

```plaintext
450 4.7.1 : Recipient address rejected: Internal error, API request preparation failed

```

---

_[View the full topic](https://meta.discourse.org/t/trying-to-setup-direct-delivery-of-incoming-email-and-new-topic-by-email/310674)._
