如何设置 SMTP 服务器以允许向任何收件人发送邮件?

如何设置 SMTP 服务器以允许向任何收件人发送邮件?

我有一台 Windows 服务器,用作 Web 服务器和邮件服务器。对于邮件服务器,我使用 hmailserver,接收邮件时效果很好,但发送电子邮件时效果不佳,因为我无法在该机器上设置反向 DNS。

因此,我购买了一个 Ubuntu Linux VPS,配置了反向 DNS 并安装了 postfix。

现在,在 nwindows 机器中,hMailserver 中有一个选项可以指定 SMTP 中继器(Linux 机器)的主机名和端口。我这样做了,但现在我还应该在 postfix 中配置什么才能允许向任何收件人发送电子邮件?

编辑 1:我可以远程登录 SMTP 服务器,但无法执行 rcpt to 命令。输出如下:

220 mailgate.mydomain.com ESMTP Postfix (Ubuntu)
ehlo mailgate.mydomain.com
250-mailgate.mydomain.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
mail from:<[email protected]>
250 2.1.0 Ok
rcpt to:<[email protected]>
451 4.3.0 <[email protected]>: Temporary lookup failure

在 mail.log 中我看到:

Jul 30 17:23:20 mailgate postfix/smtpd[1824]: warning: non-existent:/32 is unavailable. openfile /32: no such file or directory

Jul 30 17:23:20 mailgate postfix/smtpd[1824]: warning: table lookup problem

答案1

我终于让它工作了。我不得不对位于 /etc/postfix/main.cf 的 postfix 配置文件进行一些更改

以下是完整的工作配置文件和安装步骤,允许 hMailServer 在另一台机器上使用 postfix 作为 SMTP 中继器:

我使用了最低版本的 Ubuntu 服务器 14.04。它在 2GB 硬盘、64MB RAM OpenVZ 上运行良好。

apt-get update
iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 25 -j ACCEPT 
iptables -A INPUT -m state --state NEW -m udp -p udp --dport 25 -j ACCEPT
apt-get install postfix
--> mail configuration: 2 (Internet Site )
--> System mail name: do not enter anything
vi /etc/postfix/main.cf

像这样更改 main.cf (将 yourdomain 替换为您的域名,将 yourServerIpAddress 替换为您的服务器 IP 地址):

# 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 = mailgate.yourdomain.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = $mydomain
mydestination = $myhostname, localhost, $mydomain
relayhost =
mynetworks = 127.0.0.0/8, yourServerIpAddress(also setup reverse DNS for it pointing to mailgate.yourdomain.com)
mailbox_command = procmail -a "$EXTENSION"
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
mydomain = yourdomain.com
relay_domains = $mydestination
home_mailbox = Maildir/
local_recipient_maps =
message_size_limit = 20480000

最后重启 postfix

service postfix restart

现在,从以下位置测试您的邮件服务器:http://mxtoolbox.com/diagnostic.aspx (一切都应该是绿色的)

为了进行故障排除,您可以检查 Postfix 日志文件

cat /var/log/mail.log

祝你好运!

相关内容