如何设置一个Ubuntu邮件服务器,接受来自*@*.ca的任何电子邮件,并将其转发到外部电子邮件地址?

我试图设置一个小型的Ubuntu服务器,基本上可以接受任何电子邮件,并将其全部转发到我select的电子邮件地址。
我做了一些研究,我认为这将是可能的后处理,但我真的不熟悉它。

有人可以提供一个关于如何去做这个的详细解释吗? 我从头开始从一个新的Ubuntu服务器,我已经尝试将此添加到postfixmain.cf ,但它不工作。

 luser_relay = [email protected] local_recipient_maps = 

最终的目标是创build一个指向我的服务器的MXlogging,用于我使用的所有域以及电子邮件将开始stream动(临时)。 我了解安全风险和垃圾邮件问题。

谢谢您的帮助

PS:如果有人知道任何应用程序或最简单的方法, 我愿意接受任何其他方式来做到这一点,这对我来说很有用。

此答案不接受整个“ca”TLD的邮件。 这是因为我发现VirtUser表中的通配符域需要修补m4文件。

这个答案确实提供了一个方法来获取.ca域名列表,并将接收者重写为外部地址。

安装Sendmail,启动它。

 apt-get install sendmail service sendmail start 

使所有适配器上的sendmail列表

默认情况下,sendmail将在本地主机(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 

…然后build立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 RELAY邮件:

我们需要编辑“访问”文件来告诉sendmail接受“ca”TLD的邮件。

 vim /etc/mail/access 

在其他“RELAY”语句附近添加此项。 这会导致sendmail接受任何带有“* .ca”收件人地址的邮件。

 To:ca RELAY 

保存并退出…

然后使用makemap来创buildaccess.db哈希映射文件:

 makemap hash /etc/mail/access < /etc/mail/access 

重新启动sendmail:

 service sendmail restart 

用外部服务器的telnettestingRELAY语句:

从外部服务器使用telnet手动testing“* .ca”收件人:

 telnet your_mail.server 25 

以下是我在远程login会话中input的命令:

 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] 

那么有些东西是不行的

configuration了virtusertable和virtuser-domains

为了重写我们的.ca域的任何传入电子邮件的接收者,我们使用了virtusertable。

首先我们再次编辑sendmail.mc来启用一些function:

 vim /etc/mail/sendmail.mc 

find这一行:

 FEATURE(`access_db', , `skip')dnl` 

…并在其后添加以下几行…

 FEATURE(`virtusertable')dnl VIRTUSER_DOMAIN_FILE(`/etc/mail/virtuser-domains')dnl FEATURE(`virtuser_entire_domain')dnl 

注意:FEATURE()语法从反引号开始并以单引号结尾

… 保存并退出 …

编译configuration文件:

 m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf 

将域添加到virtuser-domains文件中:

我们需要告诉sendmail应该在virt用户表中查看哪些域。 由于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 -bvtesting重写

您可以使用服务器上的sendmail进行testing,以确保符合预期的可执行规则正常工作:

 root@dib:/etc/mail# sendmail -bv [email protected] [email protected]... deliverable: mailer esmtp, host gmail.com., user [email protected] 

testing实际的电子邮件:

在外部服务器上再次运行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 

谷歌“灰色上市”我很快…我想…

所以,我的第一封电子邮件testing已经通过了,并被放入垃圾邮件 每次testing之后,我都会从gmail服务器获取4xx(延期)代码。 这是有道理的,因为这看起来像海拉垃圾邮件的东西…

邮件最终通过了,但花了几分钟。 发行4xx代码是邮件服务器用来“限制”发送垃圾邮件的服务器的一种方式。

您可能希望在接收服务器上设置白名单规则,因为这些邮件会像垃圾一样看起来像垃圾邮件一样。

在sendmail日志中看起来如此:

请注意,这是与日志级别“20”,因为它显示locking的消息,我正在排除故障:

 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