Email

用於基於別名的轉發的簡單 SMTP 伺服器

  • January 22, 2013

我正在尋找一個僅用於轉發一些電子郵件地址的 SMTP 伺服器。兩個要求:

  1. 易於在 Ubuntu 上安裝和配置。
  2. 有一個易於自動添加的別名文件。理想情況下,這將是一個文本文件,由諸如“foo@myserver.com mrfoo@gmail.com”之類的行組成。
  3. (理想情況下)可以輕鬆配置為僅接受來自特定主機的郵件。

我一直在嘗試 Postfix,但我陷入了諸如 and 之類的錯誤消息Recipient address rejected: User unknown in virtual alias tableRecipient address rejected: User unknown in local recipient table。所以我想知道是否有更簡單的解決方案。

  1. 使用後綴

在 ubuntu 上,執行以下操作

apt-get install postfix

我對我的 vps 電子郵件設置做同樣的事情。查看我的博文 Tiny VPS Postfix。我正在複製下面的範例

/etc/postfix/main.cf

# See /usr/share/postfix/main.cf.dist for a commented, more complete version

# Debian specific:  Specifying a file name will cause the first
# line of that file to be used as the name.  The Debian default
# 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

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

# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.

myhostname = <YOUR HOSTNAME>
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = <YOUR DOMAIN NAME>, localhost.domain, localhost
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_command = procmail -a "$EXTENSION"
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all

smtpd_recipient_restrictions =
   permit_mynetworks,
   permit_sasl_authenticated,
   reject_invalid_hostname,
   reject_non_fqdn_hostname,
   reject_non_fqdn_sender,
   reject_non_fqdn_recipient,
   reject_unknown_recipient_domain,
   reject_unlisted_recipient,
   reject_unauth_destination,
   reject_rbl_client cbl.abuseat.org,
   reject_rbl_client bl.spamcop.net,
   reject_rbl_client relays.mail-abuse.org,
   reject_rbl_client dnsbl.proxybl.org,
   reject_rbl_client truncate.gbudb.net,
   reject_rbl_client dnsbl.njabl.org,
   permit

記住改變<YOUR HOSTNAME><YOUR DOMAIN NAME> 2. 別名文件

您的/etc/aliases文件應如下所示

foo: mrfoo@gmail.com
bar: mrbar@gmail.com

左邊應該沒有域名,只有使用者名。域由您的後綴配置控制。然後執行以下操作

cd /etc
postalias aliases
service postfix restart
  1. 單主機限制

為了只允許來自單個(或幾個)主機的電子郵件,我將使用一種非常懶惰的方式來做到這一點。

假設允許傳入主機的 IP 為 IP 192.168.1.100,將其添加到mynetworks

mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 192.168.1.100

更改smtpd_recipient_restrictions為以下

smtpd_recipient_restrictions =
   permit_mynetworks,
   reject_unlisted_recipient

Postfix 僅(並且始終)接受來自mynetworks. 並拒絕其他一切。 4. DNS 配置

記得設置 MX 記錄和 spf 記錄。

引用自:https://serverfault.com/questions/471255