我正在寻找一个基于 Linux 的 SMTP 服务器。我已经阅读了有关 Postfix SASL 和 Dovecot 的教程和规范,但我找不到如何配置允许通过 SMTP 服务器发送电子邮件的用户名和密码列表 ( smtpd
)。
换句话说:
- 我应该在哪个文件中添加允许发送电子邮件的每个客户端的用户名和密码?
- 我应该指定哪种格式的用户名?用户名应该包含
@
,例如 ,[email protected]
还是不包含@
,例如username
。
这些是我搜索的来源:
我正在寻找一个基于 Linux 的 SMTP 服务器。我已经阅读了有关 Postfix SASL 和 Dovecot 的教程和规范,但我找不到如何配置允许通过 SMTP 服务器发送电子邮件的用户名和密码列表 ( smtpd
)。
换句话说:
@
,例如 ,[email protected]
还是不包含@
,例如username
。这些是我搜索的来源:
我想在 docker 容器中托管几个自动电子邮件服务,这些服务通过 Postfix 服务器发送和接收电子邮件,该服务器也在容器中。唯一面向外的容器托管 nginx 代理管理器。docker 网络将所有容器链接在一起。我将25
nginx 代理管理器中的端口流式传输到 Postfix 容器。由于我是在内部网络内发送或接收服务的电子邮件,因此我将内部网络范围添加到main.cf
mynetwork = 172.16.0.0/12
当我意识到其他随机发件人正在通过我的域转发垃圾邮件时,问题很快就出现了。原因是,当使用代理管理器进行流式传输时,Postfix 始终将传入的电子邮件视为来自代理,因此被识别为是从我的本地网络发送的,并且无论如何都会发送它。
目前的解决方案是一一输入配置
mynetwork = service-1 service-2 ...
问题是,如果我要向服务器添加更多服务,我必须手动更改配置文件并重新启动 Postfix 服务。有没有办法像这样从 Postfix 配置的权限列表中排除某些主机?
mynetwork = 172.16.0.0/12 exclude:[host-name-to-exclude]
非常感谢!
如何为我的 Postfix 邮件服务器正确颁发 Let's Encrypt 证书?现在我有一个自签名证书,我收到这些消息,它不可信。
我做了 certbot --nginx certonly -d mail.example.org ,显然它是自签名的。
我在 ubuntu 22.04 上使用 saslauthd 和 postfix 配置客户端身份验证时遇到一些问题。问题是,尽管用户存在,但用户未经过身份验证。这是我第一次设置 postfix 和 saslauthd,因此对于一些服务器故障高手来说这可能是显而易见的。
使用 mail 命令发送电子邮件工作正常。使用 telnet 一切看起来都不错,但使用具有身份验证的远程 SMTP 客户端时,它不起作用。我已经深度学习了 6 个小时,几乎要放弃了(今天)。
从远程服务器进行 telnet:
telnet mail.mydomain.com 25
Trying IP...
Connected to mail.mydomain.com.
Escape character is '^]'.
220 mail.mydomain.com ESMTP Postfix (Ubuntu)
EHLO mydomain.com
250-mail.mydomain.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-STARTTLS
250-AUTH SCRAM-SHA-1 SCRAM-SHA-256 DIGEST-MD5 NTLM CRAM-MD5 PLAIN LOGIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250-DSN
250-SMTPUTF8
250 CHUNKING
421 4.4.2 mail.mydomain.com Error: timeout exceeded
Connection closed by foreign host.
验证我创建的用户是否确实存在
testsaslauthd -u lukas -p mypassword -r mydomain.com
0: OK "Success."
/var/log/mail.log(请注意,即使上面刚刚成功测试,验证也会失败。
Mar 9 04:36:42 postfix/smtpd[42026]: warning: SASL authentication failure: Password verification failed
Mar 9 04:36:42 postfix/smtpd[42026]: warning: IPbredband.3.dk[IP]: SASL PLAIN authentication failed: authentication failure
Mar 9 04:36:42 postfix/smtpd[42026]: lost connection after AUTH from IP.bredband.3.dk[IP]
Mar 9 04:36:42 postfix/smtpd[42026]: disconnect from IP.bredband.3.dk[IP] ehlo=2 starttls=1 auth=0/1 commands=3/4
我目前正在尝试通过 nodemailer 的 SMTP 模块登录(这不应该是问题 - 但安全总比抱歉好):
import nodemailer from "nodemailer"
const transporter = nodemailer.createTransport({
host: "mail.mydomain.com",
port: 25,
secure: false, // Use `true` for port 465, `false` for all other ports
auth: {
user: "[email protected]”,
pass: “myapassword
},
});
router.post('/', async (req, res) => {
const info = await transporter.sendMail({
from: '"Maddison Foo Koch 👻" <username@mydomain>', // sender address
to: "[email protected]”, // list of receivers
subject: "Hello!", // Subject line
text: "Hello world?", // plain text body
html: "<b>Hello world?</b>", // html body
});
console.log("Message sent: %s", info.messageId);
return res.status(200).json({ data:"ok", info: JSON.stringify(info) });
});
/etc/postfix/master.cf(启用 chroot)
# ==========================================================================
# service type private unpriv chroot wakeup maxproc command + args
# (yes) (yes) (no) (never) (100)
# ==========================================================================
smtp inet n - y - - smtpd
/etc/postfix/main.cf(高度相信此文件中有问题)
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no
append_dot_mydomain = no
readme_directory = no
compatibility_level = 3.6
# TLS parameters
smtpd_tls_cert_file=/etc/letsencrypt/live/mail.mydomain.com/fullchain.pem
smtpd_tls_key_file=/etc/letsencrypt/live/mail.mydomain.com/privkey.pem
smtpd_tls_security_level=may
smtp_tls_CApath=/etc/ssl/certs
smtp_tls_security_level=may
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
# auth
#smtpd_sasl_path = smtpd
smtpd_sasl_type = cyrus
smtpd_sasl_path = var/run/saslauthd/mux
#smtpd_sasl_path = var/run/saslauthd/saslauthd/mux
#smtpd_sasl_path = /var/spool/postfix/var/run/saslauthd/saslauthd
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname
smtpd_relay_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = mail.mydomain.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = $myhostname, mydomain.com, localhost.com, localhost
relayhost =
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
/etc/postfix/sasl/smtpd.conf
pwcheck_method: saslauthd
mech_list: plain login
/etc/默认/saslauthd
START=yes
DESC="SASL Authentication Daemon"
NAME="saslauthd"
MECHANISMS="sasldb"
MECH_OPTIONS=""
THREADS=5
OPTIONS="-c -m /var/run/saslauthd"
此外, /var/run/saslauthd 和 /var/spool/postfix/var/run/saslauthd 之间存在符号链接
非常感谢任何提示或帮助!
有些电子邮件托管商是混蛋。无论您的黑名单是 SPK、DKIM 还是 DMARC,它们都会阻止您的电子邮件。
为了解决这个问题,我使用设置了一个中继sender_dependent_relayhost_maps
。我们的中继有多个具有不同用户名/密码的域。例如,以下是 上的两个域smtp_sasl_password_maps
:
@example.com user1/pass1
@example.net user2/pass2
现在,因为我想与那些混蛋电子邮件主机合作来解决问题,所以我添加了自己的电子邮件,如下所示sender_dependent_relayhost_maps
:
[email protected] DUNNO
example.com relay
example.net relay
一般来说,这是可行的,但是当我使用 发送电子邮件时[email protected]
,postfix 会尝试使用 user1/pass1 与不是中继的服务器进行身份验证。
文档说:
如果未找到用户名:密码条目,则 Postfix SMTP 客户端将不会尝试对远程主机进行身份验证。
有什么办法可以禁用身份验证吗?
我已经用 dovecot 安装了 postfix,之后我发现来自互联网的大量身份验证失败。我已经安装并配置了fail2ban,并且每个未经身份验证的IP都被禁止,但也许还有其他解决方案,或者也许我做错了什么。
日志示例:
Mar 8 08:48:01 somehostname auth: pam_unix(dovecot:auth): authentication failure; logname= uid=0 euid=0 tty=dovecot ruser=news rhost=45.88.90.208 user=news
是否有其他解决方案来禁用客户端从互联网登录/连接并仅从本地网络启用?- 就我而言,无需为客户从互联网检索电子邮件。也许还有其他解决方案?
postfix main.cf 中的 Dovecot 示例配置:
smtpd_sasl_type = dovecot
提前谢谢你AD
我发送电子邮件的目的地之一具有不寻常的性能特征。活动队列可能会填满该域的消息,从而阻止发送到其他域。我想限制该域使用的活动队列中的插槽数量。
作为临时措施,该域的流量通过专用中继进行路由,我在其中设置:
default_recipient_refill_limit=50
default_recipient_limit=1000
活动队列大小的上限仍然是默认的 20000。按照上面修改 main.cf 后,我运行了 apostfix check
和systemctl reload postfix
。日志显示重新加载事件。
然而,我的监控显示,几个小时后,Active队列在2分钟的窗口内跃升至20000。即消息的速率和上限似乎都没有被应用。它在20000处保持了几分钟。
监控是通过 check_MK 进行的 - 虽然我很容易相信它可能报告了传入队列和活动队列的计数,但 20000 处的稳定状态表明情况并非如此。
我在这里缺少什么?/ 如何限制消息从传入状态转移到活动状态的数量或速度?
(我需要一个可以使用自定义传输实现的解决方案,以便我可以通过共享中继将流量移回)。
这是在 Amazon Linux 2 上运行的 Postfix 2.10,MTA 上没有配置将在活动队列中扩展的通讯组列表。请注意,我不是在问如何更快地将邮件传递到该域 - 我是在问如何限制活动队列中关联邮件的数量。
我有一个工作后缀 3.5 中继,其中配置包括:
smtpd_client_restrictions = permit_mynetworks,
reject_unknown_client_hostname,
permit
smtpd_helo_required=yes
smtpd_helo_restrictions = reject_unknown_helo_hostname
reject_invalid_helo_hostname
smtpd_recipient_restrictions = permit_mynetworks,
permit_sasl_authenticated
smtpd_relay_restrictions = permit_mynetworks, permit_sasl_authenticated,
reject_unauth_destination
我在日志中看到频繁的身份验证尝试:
2月23日16:53:02 m.example.com postfix/smtpd[30155]:从未知连接[196.190.41.137]
2月23日16:53:17 m.example.com postfix/smtpd[30155]:警告:未知[ 196.190.41.137]:SASL LOGIN 身份验证失败:身份验证失败
2 月 23 日 16:53:19 m.example.com postfix/smtpd[30155]:未知身份验证后失去连接[196.190.41.137]
2 月 23 日 16:53:19 m .example.com postfix/smtpd[30155]:与未知[196.190.41.137]断开连接 ehlo=2 starttls=1 auth=0/1 命令=3/4
我希望这reject_unknown_helo_hostname
会立即拒绝,但它似乎允许他们尝试 SASL 登录。虽然我认为我的 saslauth 相当安全,但我宁愿他们甚至不能尝试。
有没有办法让“未知”主机名更早被拒绝?这将阻止 90% 的登录尝试,因为大多数不断尝试相同登录的僵尸网络都具有未知的主机名。
我的配置中是否有某些内容过于宽松,因此他们始终可以执行 saslauth 步骤?
各种 SMTP 访问限制的应用顺序是什么?
编辑:Wireshark 显示最近的这些 SASL 登录身份验证失败之一发送此消息来启动会话:
EHLO [182.150.23.17]
那么为什么在这件事发生之前没有被拒绝:
2 月 23 日 23:49:42 m.example.com postfix/smtpd[42557]:警告:未知[182.150.23.17]:SASL LOGIN 身份验证失败:身份验证失败
在运行 Postfix 的邮件服务器上,我想拒绝主题中使用一些非拉丁文字的邮件,特别是阿拉伯语和西里尔语,因为我的用户(家庭)都不会说使用它们的语言。
我尝试使用 PCRE 标头检查,如下所示:
/Subject:.*\p{Arabic}/i WARN Arabic detected
不幸的是,当我向服务器发送测试邮件时,这不会触发警告。我已经WARN
使用规则验证了消息确实出现在系统日志中/Subject:.*Test/i WARN Test
,该规则确实触发了。
如何使用 Postfix 检测主题中的阿拉伯语和西里尔语?
为了完整起见,main.cf
我在我的内容中包括header_checks
这样的内容:
header_checks = pcre:/etc/postfix/header_checks
我正在运行一个OSticket支持系统,该系统利用Mailcow堆栈进行电子邮件消息传递。
一切工作正常,除了由于邮箱问题等原因我们无法向票证作者发送电子邮件的情况。
在这些情况下,会发生以下情况:
在 OSTicket 端查看这一点,似乎 OSticket会尝试将弹回与原始机票相匹配。。然而,我的电子邮件方面的默认配置不包括OSticket 期望的必需标头。
我想解决这个问题,似乎添加额外的标头可能有助于 OSTicket 认识到这是一个反弹。
我对 postfix 很陌生,所以我不知道如何做到这一点,但我很确定它是可行的。
谁能帮我弄清楚如何配置这个?谢谢你!
我已经包含了一封退回电子邮件的完整原始来源,它经过大量编辑,但也许标头会有所帮助。
Return-Path: <>
Delivered-To: [REDACTED]
Received: from [REDACTED] ([[REDACTED]])
by 847cc1941aed with LMTP
id wPAfFiLbwmWYrwYAydh85g
(envelope-from <>)
for <[REDACTED]>; Wed, 07 Feb 2024 01:21:38 +0000
Received: by [REDACTED] (Postcow)
id 5482521BF8E2; Wed, 7 Feb 2024 01:21:38 +0000 (UTC)
Date: Wed, 7 Feb 2024 01:21:38 +0000 (UTC)
From: MAILER-DAEMON@[REDACTED] (Mail Delivery System)
Subject: Undelivered Mail Returned to Sender
To: [REDACTED]
Auto-Submitted: auto-replied
MIME-Version: 1.0
Content-Type: multipart/report; report-type=delivery-status;
boundary="CA4EC21BFE80.1707268898/[REDACTED]"
Message-Id: <20240207012138.5482521BF8E2@[REDACTED]>
This is a MIME-encapsulated message.
--CA4EC21BFE80.1707268898/[REDACTED]
Content-Description: Notification
Content-Type: text/plain; charset=us-ascii
This is the mail system at host [REDACTED].
I'm sorry to have to inform you that your message could not
be delivered to one or more recipients. It's attached below.
For further assistance, please send mail to postmaster.
If you do so, please include this problem report. You can
delete your own text from the attached returned message.
The mail system
<[REDACTED]>: connect to [REDACTED][[REDACTED]]:25:
Connection timed out
--CA4EC21BFE80.1707268898/[REDACTED]
Content-Description: Delivery report
Content-Type: message/delivery-status
Reporting-MTA: dns; [REDACTED]
X-Postcow-Queue-ID: CA4EC21BFE80
X-Postcow-Sender: rfc822; [REDACTED]
Arrival-Date: Fri, 2 Feb 2024 01:10:13 +0000 (UTC)
Final-Recipient: rfc822; [REDACTED]
Original-Recipient: rfc822;[REDACTED]
Action: failed
Status: 4.4.1
Diagnostic-Code: X-Postcow; connect to [REDACTED]:25:
Connection timed out
--CA4EC21BFE80.1707268898/[REDACTED]
Content-Description: Undelivered Message
Content-Type: message/rfc822
Return-Path: <[REDACTED]>
Received: from [[REDACTED]] (localhost [[REDACTED]]) by [REDACTED] (Mailerdaemon) with ESMTPSA id CA4EC21BFE80;
Fri, 2 Feb 2024 01:10:13 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=[REDACTED];
s=dkim; t=1706836214;
h=from:subject:date:message-id:to:cc:mime-version:content-type;
bh=[REDACTED]
b=[REDACTED]
Date: Fri, 02 Feb 2024 01:10:13 +0000
Message-ID: <BKAfB/m-40f2Z-AAAAAGINAACIBAAATe4OlSy5-[REDACTED]>
From: =?utf-8?Q?[REDACTED]?= <[REDACTED]>
Subject: =?UTF-8?Q?Re:=[REDACTED]?=
To: =?utf-8?Q?[REDACTED]?= [REDACTED]
Cc: =?utf-8?Q?[REDACTED]?= [REDACTED]
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="=_9875f05c0d2ad638ed6e39eb808b5ce5"
X-Last-TLS-Session-Version: TLSv1.3
This is a message in Mime Format. If you see this, your mail reader does not support this format.
--=_9875f05c0d2ad638ed6e39eb808b5ce5
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: base64
[REDACTED]
--=_9875f05c0d2ad638ed6e39eb808b5ce5--
--CA4EC21BFE80.1707268898/[REDACTED]--