在本地计算机中配置 postfix 以发送邮件

在本地计算机中配置 postfix 以发送邮件

我正在尝试自动化一个过程,当满足特定条件时,我想使用以下命令通过自动邮件通知用户邮件命令。

问题是,消息没有被发送,据我了解,必须首先进行一些配置。

问题是当我去的时候

sudo dpkg-reconfigure postfix

为了修改它,我不完全确定在那里填写什么。

  • 1 - 第一页询问系统邮件名称
  • 2 - 第二个请求 root 和 postmaster 邮件收件人
  • 3 - 其他接受邮件的目的地
  • 4 - 强制同步邮件队列是/否
  • 5 - 本地网络(这是预先填写的)
  • 6 - 邮箱大小
  • 7 - 本地地址扩展字符
  • 8 - 协议(ipv6、ipv4)# I selected them both

但我确实需要 1、2、3、5、7 方面的帮助,因为当我尝试发送测试邮件时,我没有收到任何内容

先感谢您

更新:

操作系统信息

NAME="Ubuntu"
VERSION="20.04 LTS (Focal Fossa)"

后缀版本

mail_version = 3.4.10

会议后

alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
append_dot_mydomain = no
biff = no
compatibility_level = 2
inet_interfaces = all
inet_protocols = all
mailbox_size_limit = 100
mydestination = aoos.homenet.telecomitalia.it, aoos, localhost.localdomain, , localhost
myhostname = aoos.homenet.telecomitalia.it
myorigin = /etc/mailname
readme_directory = no
recipient_delimiter =
relayhost =
smtp_tls_CApath = /etc/ssl/certs
smtp_tls_security_level = may
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
smtpd_tls_cert_file = /etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file = /etc/ssl/private/ssl-cert-snakeoil.key
smtpd_tls_security_level = may

邮件q

-Queue ID-  --Size-- ----Arrival Time---- -Sender/Recipient-------
DD866CE073F*    2566 Sun May 10 18:17:10  MAILER-DAEMON
                                         broxigar@aoos

DA34ECE0693*    2493 Fri May 15 19:08:58  MAILER-DAEMON
                                         broxigar@aoos

D474DCE0692*    2531 Fri May 15 19:08:58  MAILER-DAEMON
                                         broxigar@aoos

CFCC4CE0690*    2491 Fri May 15 19:08:58  MAILER-DAEMON
                                         broxigar@aoos

0DC1FCE0738*    2398 Sun May 10 18:05:51  MAILER-DAEMON
                                         broxigar@aoos

D06F9CE0691*    2497 Fri May 15 19:08:58  MAILER-DAEMON
                                         broxigar@aoos

3534ECE068E      417 Fri May 15 17:01:06  broxigar@aoos
(host mx.<domain_name>.it[130.192.182.65] said: 452 4.5.2 Could not resolve sender domain. (in reply to MAIL FROM command))
                                         userXXX@<domain_name>.it

编辑后(postconf -n)

# is /etc/mailname.
#myorigin = /etc/mailname

smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

readme_directory = no

# See http://www.postfix.org/COMPATIBILITY_README.html -- default to 2 on
# fresh installs.
compatibility_level = 2

# TLS parameters
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtp_use_tls = yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtp_tls_wrappermode = yes
smtp_tls_security_level = encrypt

#smtp_tls_CApath=/etc/ssl/certs
#smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
#smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
#smtp_sasl_auth_enable = yes
#smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
#smtp_sasl_security_options = noanonymous
#smtp_tls_security_level = encrypt
#smtp_tls_wrappermode = yes


smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = aoos.polito.it
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = $myhostname, aoos.polito.it, localhost.polito.it, localhost

#myorigin = $mydomain 
relayhost = [mail.polito.it]:465
#relay_domains = $mydestination
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = all

编辑后(mailq)

-Queue ID-  --Size-- ----Arrival Time---- -Sender/Recipient-------
64428CE10EA*    2334 Fri Jun 19 22:55:27  MAILER-DAEMON
                                         broxigar@aoos

编辑后(journalctl -xe)

Jun 19 22:55:29 aoos postfix/smtp[1158006]: 64428CE10EA: to=<broxigar@aoos>, relay=server.domain.it[<ip_addr>]:465, delay=2, delays=0.01/0/0.03/2, dsn=5.0.0, status=bounced (host server.domain.it[<ip_addr>] said: 551 broxigar@aoos failed to route the address (in reply to RCPT TO command))

答案1

[免责声明:以下内容针对 Postfix v3.5.1 进行了全面测试。在最新的 Arch Linux 安装上。 Ubuntu 20.04 上的 Postfix v3.4.10 的故障排除应该非常相似,除了(可能)一些硬编码在main.cf和/或中的文件路径master.cf。]

我看到以 开头的参数设置smtpd_...。仅当您的主机的本地后缀设置能够处理时,这才是必要的传入电子邮件。如果你只想发送通过 smtp 中继发送电子邮件,您可以将其注释掉。

错误452: 无法解析发件人域。 (回复 MAIL FROM 命令) userXXX@\< domain_name>.it

您的本地主机的域名未正确解析。显然,从您的问题的编辑来看,它的设置不正确。添加以下内容或修改现有配置/etc/postfix/main.cf

append_at_myorigin = yes
append_dot_mydomain = ${{$compatibility_level} < {1} ? {yes} : {no}}
tls_append_default_CA = no
inet_interfaces = $myhostname, localhost  
                                  # might speed up your sending process if your host 
                                  # is part of a subnet with other hosts.
mydestination = $myhostname, localhost.$mydomain, localhost
mydomain = aoos                   # confirm that's the local domain name you chose 
myhostname = localhost
mynetworks_style = subnet
myorigin = $mydomain
relay_domains = $mydestination
relayhost = [smtp.gmail.com]:465  # << only when using gmail as smtp server.
                                  # Replace with your own smtp  server.  Always include
                                  # square brackets as shown + optional port.
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
                                  # or use 'smtp_tls_CApath = /etc/ssl/certs' as shown by you
smtp_tls_security_level = encrypt # Use either 'encrypt' or 'may'
smtp_tls_wrappermode = yes        # Poorly or not documented, but necessary when 
                                  # using TLS with Google's smtp outgoing mail gateway
smtp_use_tls = yes

除了上述内容之外,您还需要保护您使用的 smtp 网关的用户名和密码,在/etc/postfix/sasl_passwd.下面我提供了 smtp.gmail.com 的示例:

$ cat /etc/postfix/sasl_passwd
[smtp.gmail.com]:465  <my_username>@gmail.com:<my_passwd>
$ sudo chmod 600 /etc/postfix/sasl_passwd
$ sudo postmap /etc/postfix/sasl_passwd  

编辑#1:还可以这样做:$ sudo chown root:postfix /etc/postfix/sasl_passwd*

我假设您postfix已经启用并启动了该服务。如果未启用,请执行以下操作:sudo systemctl enable postfix

重新加载配置参数并重启postfix服务:

$ sudo postfix reload
$ sudo systemctl restart postfix.service

最后尝试发送电子邮件:

$ touch foobar
$ mail -s "test #<my_test_nbr>" -a foobar <my_external_email> < <(echo "Hello world")
$ journalctl -xe    # report relevant warnings & errors   (***EDIT***)
$ mailq             # report full output

如果您有更多问题,请报告。 HTH。


编辑#2: 我从您使用 postfix 发送邮件的尝试中看到,发送是通过 IPv6 进行的。 RFC-6724 指示如果计算机是双堆栈的(其中 IPv4 和 IPv6 协议在同一网络基础设施上运行),则应首先尝试连接到 IPv6。您很可能有这样的设置。 AFAIK,Google 接受通过 IPv6 的 stmp 请求,但前提是请求源提供了用于认证的反向域名目的。您无法从 MTA 方面控制它;它掌握在您的 ISP 手中。因此,如果我是您,我会首先尝试通过 IPv4 进行发送,然后尝试使用 IPv6。为此,至少为了使用 gmail 进行测试,请更改/etc/postfix/main.cf为:

inet_protocols = ipv4

这并不意味着您的所有 IP 连接都必须使用 IPv4。如果您仍然需要 IPv6(gmail 除外),则可以postfix使用地图来解决此问题;transport也许您想在不同的帖子中提出不同的问题。

相关内容