我正在尝试设置一个小型 Ubuntu 服务器,它可以接收基本上任何电子邮件,并将它们全部转发到我选择的电子邮件地址。
我做了一些研究,我认为可以使用 来实现postfix
,但我真的不熟悉它。
有人能详细解释一下我该怎么做吗?我从一台全新的 Ubuntu 服务器开始,我尝试将其添加到主配置文件但postfix
它不起作用。
luser_relay = [email protected]
local_recipient_maps =
最终目标是,我只需为我使用的所有域名创建一个指向我的服务器的 MX 记录,然后电子邮件就会开始流动(暂时)。我了解安全风险和垃圾邮件问题。
谢谢您的帮助
附言:我愿意接受任何其他方式,如果有人知道任何应用程序或最简单的方法来做到这一点,它对我来说就有用了。
答案1
此答案不接受整个“ca”TLD 的邮件。这是因为我发现 VirtUser 表中的通配符域需要修补 m4 文件。
这个答案确实提供了一种获取 .ca 域列表并将收件人重写为外部地址的方法。
安装 Sendmail,并启动它。
apt-get install sendmail
service sendmail start
在所有适配器上制作 sendmail 列表
默认情况下,sendmail 会监听 localhost (127.0.0.1)。我们需要编辑 sendmail.mc,让它监听所有 IP。
vim /etc/mail/sendmail.mc
改变:
DAEMON_OPTIONS(`Family=inet, Name=MTA-v4, Port=smtp, Addr=127.0.0.1')dnl
... 到 ...
DAEMON_OPTIONS(`Family=inet, Name=MTA-v4, Port=smtp, Addr=0.0.0.0')dnl
...然后构建 sendmail.cf 文件:
m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
...然后重新启动sendmail:
service sendmail restart
现在我们需要确认 sendmail 正在监听所有适配器。使用 netstat,您应该得到如下结果:
netstat -tpln
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
...
tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 6104/sendmail: MTA:
...
为“ca”TLD 制作 sendmail 中继邮件:
我们需要编辑“access”文件来告诉 sendmail 接受“ca”TLD 的邮件。
vim /etc/mail/access
在其他“RELAY”语句的任意位置添加此语句。这将使 sendmail 接受任何带有“*.ca”收件人地址的邮件。
To:ca RELAY
保存并退出...
然后使用 makemap 制作 access.db 哈希映射文件:
makemap hash /etc/mail/access < /etc/mail/access
重新启动sendmail:
service sendmail restart
从外部服务器使用 telnet 测试 RELAY 语句:
从外部服务器使用 telnet 手动测试“*.ca”收件人:
telnet your_mail.server 25
以下是我在 telnet 会话中输入的命令:
helo testing.com
mail from: [email protected]
rcpt to: [email protected]
quit
以下是输出的示例:
root@zim:~# telnet dib.ttucker.net 25
Trying 52.43.174.20...
Connected to dib.ttucker.net.
Escape character is '^]'.
220 localhost ESMTP Sendmail 8.15.2/8.15.2/Debian-3; Mon, 5 Jun 2017 04:36:55 GMT; (No UCE/UBE) logging access from: [23.227.163.72](FORGED)-billing.bizzhost.com [23.227.163.72] (may be forged)
helo testing.com
250 localhost Hello billing.bizzhost.com [23.227.163.72] (may be forged), pleased to meet you
mail from: [email protected]
250 2.1.0 [email protected]... Sender ok
rcpt to: [email protected]
250 2.1.5 [email protected]... Recipient ok
quit
221 2.0.0 localhost closing connection
Connection closed by foreign host.
如果你看到这个:
rcpt to: [email protected]
550 5.7.1 [email protected]... Relaying denied. IP name possibly forged [23.227.163.72]
... 那么有些事情就不起作用了...
配置 virtusertable 和 virtuser-domains
为了重写我们的 .ca 域名的任何来电电子邮件的收件人,我们使用了 virtusertable。
首先我们再次编辑 sendmail.mc 以启用一些功能:
vim /etc/mail/sendmail.mc
找到以下行:
FEATURE(`access_db', , `skip')dnl`
...并在其后添加以下几行...
FEATURE(`virtusertable')dnl
VIRTUSER_DOMAIN_FILE(`/etc/mail/virtuser-domains')dnl
FEATURE(`virtuser_entire_domain')dnl
注意:FEATURE() 语法以反引号开头,以单引号结尾
... 保存并退出 ...
编译配置文件:
m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
将域添加到 virtuser-domains 文件:
我们需要告诉 sendmail 它应该在虚拟用户表中查找哪些域。由于 sendmail 对域执行最佳左手匹配,因此我们可以在此处只输入 TLD“ca”...
vim /etc/mail/virtuser-domains
...添加“ca”域:
ca
...(是的,该文件只包含“ca”)...保存并退出
将重写添加到 virtusers 表:
接下来我们需要告诉 sendmail 要进行哪些重写。我们将这些添加到 virtusertable。如上所述,您需要手动或使用脚本将每个域添加到此文件。
vim /etc/mail/virtusertable
...添加您的域名:
@derp.ca [email protected]
@another.ca [email protected]
@sendmail.ca [email protected]
... 保存并退出 ...
现在我们需要再次使用 makemap:
makemap hash /etc/mail/virtusertable < /etc/mail/virtusertable
注意:您现在应该有一个 /etc/mail/virtusertable.db 文件
...重新启动sendmail:
service sendmail restart
使用 sendmail -bv 测试重写
您可以在服务器上使用 sendmail 进行测试,以确保 virtusertable 规则按预期工作:
root@dib:/etc/mail# sendmail -bv [email protected]
[email protected]... deliverable: mailer esmtp, host gmail.com., user [email protected]
测试实际电子邮件:
在外部服务器上再次运行 telnet:
telnet your_email.server 25
...横幅回来后,复制并粘贴以下内容:
helo testing.com
mail from: [email protected]
rcpt to: [email protected]
data
subject: This is a test
from: [email protected]
to: [email protected]
Hello Self,
This is a test.
Regards,
.
quit
总的来说它看起来应该是这样的:
root@zim:~# telnet dib.ttucker.net 25
Trying 52.43.174.20...
Connected to dib.ttucker.net.
Escape character is '^]'.
220 dib.ttucker.net ESMTP Sendmail 8.15.2/8.15.2/Debian-3; Mon, 5 Jun 2017 06:28:46 GMT; (No UCE/UBE) logging access from: [23.227.163.72](FORGED)-billing.bizzhost.com [23.227.163.72] (may be forged)
helo testing.com
mail from: [email protected]
rcpt to: [email protected]
data
subject: This is a test
from: [email protected]
to: [email protected]
Hello Self,
This is a test.
Regards,
.
quit250 dib.ttucker.net Hello billing.bizzhost.com [23.227.163.72] (may be forged), pleased to meet you
250 2.1.0 [email protected]... Sender ok
250 2.1.5 [email protected]... Recipient ok
354 Enter mail, end with "." on a line by itself
250 2.1.0 [email protected]... Sender ok
250 2.1.5 [email protected]... Recipient ok
354 Enter mail, end with "." on a line by itself
250 2.0.0 v556SkbP009313 Message accepted for delivery
250 2.1.0 [email protected]... Sender ok
250 2.1.5 [email protected]... Recipient ok
354 Enter mail, end with "." on a line by itself
221 2.0.0 dib.ttucker.net closing connection
Connection closed by foreign host.
思考后:
您可能还想增加 sendmail 的日志级别,因为默认日志级别不是很详细。
将以下内容添加到sendmail.mc,进行编译并重新启动:
define(`confLOG_LEVEL', `14')dnl
谷歌很快就将我列入“灰名单”......我想......
因此,我的第一个电子邮件测试通过了,并被归类为垃圾邮件。此后的每次测试我都会从 gmail 服务器收到 4xx(延迟)代码。这很合理,因为这看起来像是垃圾邮件……
邮件最终还是通过了,但花了几分钟。发出 4xx 代码是邮件服务器用来“限制”垃圾邮件服务器的一种方式。
您可能需要在接收服务器上设置白名单规则,因为这些电子邮件看起来就像垃圾邮件。
这在 sendmail 日志中是这样的:
请注意,这是日志级别“20”,因为它显示锁定消息并且我正在进行故障排除:
root@dib:/etc/mail# grep v556cKKt010016 /var/log/mail.log
Jun 5 06:38:20 dib sm-mta[10016]: v556cKKt010016: Milter: no active filter
Jun 5 06:38:21 dib sm-mta[10016]: v556cKKt010016: --- 220 dib.ttucker.net ESMTP Sendmail 8.15.2/8.15.2/Debian-3; Mon, 5 Jun 2017 06:38:20 GMT; (No UCE/UBE) logging access from: [23.227.163.72](FORGED)-billing.bizzhost.com [23.227.163.72] (may be forged)
Jun 5 06:38:25 dib sm-mta[10016]: v556cKKt010016: <-- helo testing.com
Jun 5 06:38:25 dib sm-mta[10016]: v556cKKt010016: --- 250 dib.ttucker.net Hello billing.bizzhost.com [23.227.163.72] (may be forged), pleased to meet you
Jun 5 06:38:25 dib sm-mta[10016]: v556cKKt010016: <-- mail from: [email protected]
Jun 5 06:38:25 dib sm-mta[10016]: v556cKKt010016: --- 250 2.1.0 [email protected]... Sender ok
Jun 5 06:38:25 dib sm-mta[10016]: v556cKKt010016: <-- rcpt to: [email protected]
Jun 5 06:38:25 dib sm-mta[10016]: v556cKKt010016: --- 250 2.1.5 [email protected]... Recipient ok
Jun 5 06:38:25 dib sm-mta[10016]: v556cKKt010016: <-- data
Jun 5 06:38:25 dib sm-mta[10016]: v556cKKt010016: --- 354 Enter mail, end with "." on a line by itself
Jun 5 06:38:25 dib sm-mta[10016]: v556cKKt010016: [email protected], size=110, class=0, nrcpts=1, msgid=<[email protected]>, proto=SMTP, daemon=MTA-v4, relay=billing.bizzhost.com [23.227.163.72] (may be forged)
Jun 5 06:38:25 dib sm-mta[10016]: v556cKKt010016: --- 250 2.0.0 v556cKKt010016 Message accepted for delivery
Jun 5 06:38:25 dib sm-mta[10020]: v556cKKt010016: makeconnection (gmail-smtp-in.l.google.com. [IPv6:2607:f8b0:400e:c04:0:0:0:1a]) failed: Network is unreachable
Jun 5 06:40:25 dib sm-mta[10020]: v556cKKt010016: makeconnection (gmail-smtp-in.l.google.com. [173.194.202.26]) failed: Connection timed out with gmail-smtp-in.l.google.com.
Jun 5 06:40:26 dib sm-mta[10020]: v556cKKt010016: makeconnection (alt1.gmail-smtp-in.l.google.com. [IPv6:2607:f8b0:4001:c1a:0:0:0:1b]) failed: Network is unreachable
Jun 5 06:42:26 dib sm-mta[10020]: v556cKKt010016: makeconnection (alt1.gmail-smtp-in.l.google.com. [173.194.196.26]) failed: Connection timed out with alt1.gmail-smtp-in.l.google.com.
Jun 5 06:42:26 dib sm-mta[10020]: v556cKKt010016: makeconnection (alt2.gmail-smtp-in.l.google.com. [IPv6:2607:f8b0:4002:c03:0:0:0:1b]) failed: Network is unreachable
Jun 5 06:44:26 dib sm-mta[10020]: v556cKKt010016: makeconnection (alt2.gmail-smtp-in.l.google.com. [173.194.219.27]) failed: Connection timed out with alt2.gmail-smtp-in.l.google.com.
Jun 5 06:44:26 dib sm-mta[10020]: v556cKKt010016: makeconnection (alt3.gmail-smtp-in.l.google.com. [IPv6:2607:f8b0:400d:c0c:0:0:0:1a]) failed: Network is unreachable
Jun 5 06:44:26 dib sm-mta[10020]: v556cKKt010016: SMTP outgoing connect on ip-172-31-42-65.us-west-2.compute.intern
Jun 5 06:44:27 dib sm-mta[10020]: v556cKKt010016: [email protected], delay=00:06:02, xdelay=00:06:02, mailer=esmtp, pri=120110, relay=alt3.gmail-smtp-in.l.google.com. [173.194.68.26], dsn=2.0.0, stat=Sent (OK 1496645067 v28si8540518qth.285 - gsmtp)
Jun 5 06:44:27 dib sm-mta[10020]: v556cKKt010016: done; delay=00:06:02, ntries=1