简单的SMTP服务器,用于基于别名的转发

我正在寻找一个SMTP服务器,将被用来转发几个电子邮件地址。 两个要求:

  1. 易于在Ubuntu上安装和configuration。
  2. 有一个很容易自动添加的别名文件。 理想情况下,它将是一个由“[email protected] [email protected]”等行组成的文本文件。
  3. (理想情况下)可以很容易地configuration为只接受来自特定主机的邮件。

我一直在尝试Postfix,但我越来越陷入错误消息像Recipient address rejected: User unknown in virtual alias tableRecipient address rejected: User unknown in local recipient table 。 所以我想知道是否有一个更简单的解决scheme。

  1. 使用Postfix

    在Ubuntu上,请遵循以下步骤

     apt-get install postfix 

    我正在做我的vps电子邮件设置完全相同的事情。 检查我的博客post微小的VPS后缀 。 我正在复制下面的例子

    /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: [email protected] bar: [email protected] 

    左侧应该没有域名,只有用户名。 该域是由您的后缀configuration控制。 然后做下面

     cd /etc postalias aliases service postfix restart 
  3. 单个主机限制

    为了只允许来自单个(或几个)主机的电子邮件,我将使用一种非常懒惰的方式来做到这一点。

    假设允许的传入主机的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 

    只有后缀(并且总是)接受来自我的networking中列出的主机的电子邮件。 并拒绝一切。

  4. DNSconfiguration

    请记住设置MXlogging和SPFlogging。

我以类似的方式使用Postfix转发到另一台服务器。 使用三个configuration选项,但对于你的configuration有一个更简单的方法。

  • relay_recipient_maps = ldap:/etc/postfix/ldap_relay_recipients_maps.cf
  • transport_maps = ldap:/etc/postfix/ldap_transport_maps.cf
  • relay_domains = ldap:/etc/postfix/ldap_relay_domains.cf

我的一个LDAP文件看起来像这样在Zimbra上查询LDAP源代码

 server_host=ldap://[mail.domain.com]:389 server_port=389 search_base= query_filter = (&(|(zimbraMailDeliveryAddress=%s)(zimbraMailAlias=%s)(zimbraMailCatchAllAddress=%s))(zimbraMailStatus=enabled)) result_attribute = zimbraMailDeliveryAddress,zimbraMailAlias version = 3 ldap_cache = yes ldap_cache_expiry = 600 ldap_cache_size = 64256 bind = yes bind_dn = uid=[valid login],cn=[valid cn],cn=[valid cn] bind_pw = [a valid password] timeout = 30 

然而,根据你正在寻找的东西,将信息保存在可用于此目的的本地散列表中会更容易。 唯一需要记住的是,当你对这些文件进行修改时,你需要重新运行postmap来构build后缀友好的哈希表。

  • relay_recipient_maps = hash:/ etc / postfix / relay_recipients_maps
  • relay_domains = fwddomain.com
  • transport_maps = hash:/ etc / postfix / transport_maps

您需要使用以下条目对在上述位置创build文本文件:{[电子邮件地址]确定}

 [email protected] OK [email protected] OK [email protected] OK 

在上面的文件中运行postmap以生成实际的哈希文件,然后在与relay_recipients_maps.db相同的文件夹中创build哈希文件。 现在,Postfix将检查这个文件的有效收件人传递。

然后你需要告诉Postfix在收到这个域时发送邮件的地址。 使用/ etc / postfix / transport_maps文件执行相同的操作,可以input作为电子邮件将要发往的域的vaild对,并将主机转发给它。

 fwddomain.com smtp:mail.fwddomain.com 

希望这有助于指导你正确的方向。 关于如何在互联网上执行这些types的configuration文件还有更多的信息,其他人甚至可以使用数据库查找这些configuration选项。