使用 Postfix 通过多个 Google Apps 帐户进行中继

使用 Postfix 通过多个 Google Apps 帐户进行中继

我正在设置一个 Web 应用,该应用需要通过使用 Google Apps 的域上的两个不同电子邮件地址发送电子邮件。我使用 Postfix 作为中继,因为我对它相当熟悉。

但是,我很难弄清楚如何让这个功能在同一个域中与两个不同的电子邮件地址一起工作。我的印象是,您需要在 /etc/postfix/sasl 中设置两个不同的密码文件(我已经这样做了),然后将 smtp_sasl_password_maps 设置为 hash:/etc/postfix/sasl/passwd,但我不太确定两个不同文件所需的语法。我尝试按如下方式设置它:

smtp_sasl_password_maps = hash:/etc/postfix/sasl/passwd, hash:/etc/postfix/sasl/passwd2

但这似乎不起作用。我也尝试过将两者放在一个文件中,但也没有用。无论我尝试哪种方法,它似乎都只能找到一个地址。谷歌似乎也对这个问题没有什么帮助?

有人能看出我哪里走错了吗?

编辑:也许我不太清楚我想做什么。

example.com 的网络服务器安装了 Postfix,但 MX 记录指向 Google Apps。有两个电子邮件地址,[电子邮件保护][电子邮件保护],并且这两个地址都在 Google Apps 上。我想要做的是将 Postfix 配置为使用 Google Apps 作为这两个电子邮件地址的中继。

问题是我不知道如何为这两个帐户设置密码映射,因此我只能为其中一个设置密码映射,而不能同时为两个帐户设置密码映射。

答案1

您需要启用发送者相关认证这样 Postfix 就会根据所传递消息的发件人选择适当的凭据。密码映射应该由发件人地址而不是中继主机键入。

main.cf

smtp_sender_dependent_authentication = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_password_maps

sasl_password_maps

[email protected] [email protected]:password123
[email protected] [email protected]:password456

答案2

发送者相关的身份验证可以提供帮助。官方文档中有很好的例子

Postfix 支持为不同的发件人地址使用不同的 ISP 帐户(2.3 版及更高版本)。当一个人使用同一台机器用于工作和个人用途,或当拥有不同 ISP 帐户的人共享同一台 Postfix 服务器时,此功能非常有用。

为了实现这一点,Postfix 支持每个发送方 SASL 密码和每个发送方中继主机。在下面的示例中,Postfix SMTP 客户端将先按发送方地址搜索 SASL 密码文件,然后再按目的地搜索该文件。同样,Postfix trivial-rewrite(8) 守护进程将搜索每个发送方中继主机文件,并且仅在万不得已的情况下才使用默认中继主机设置。

/etc/postfix/main.cf:

smtp_sender_dependent_authentication = yes
sender_dependent_relayhost_maps = hash:/etc/postfix/sender_relay
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
relayhost = [mail.isp.example]
# Alternative form:
# relayhost = [mail.isp.example]:port

在 /etc/postfix/sasl_passwd 中:

# Per-sender authentication; see also /etc/postfix/sender_relay.
[email protected]               username1:password1
[email protected]               username2:password2
# Login information for the default relayhost.
[mail.isp.example]              username:password
# Alternative form:
# [mail.isp.example]:port username:password

在/etc/postfix/sender_relay中:

# Per-sender provider; see also /etc/postfix/sasl_passwd.
[email protected]               [mail.example.com]:port
[email protected]               [mail.example.net]
  • 每当您更改 sasl_passwd 表时,执行命令“postmap /etc/postfix/sasl_passwd”。
  • 每当您更改 sender_relay 表时,执行命令“postmap /etc/postfix/sender_relay”。

答案3

我使用了不同的方法。我的问题是:由于 Gmail 限制 10000 封电子邮件/24 小时,我必须在两个 Google 帐户之间切换,我在 crontab 上创建了“sasl_passwd.db_user1”和“sasl_passwd.db_user2”,并创建了一个脚本,将“sasl_passwd.db_user1”复制到“sasl_passwd.db”中并重新启动 postfix。另一个脚本将“user2”复制到“sasl_passwd.db”。

相关内容