我有一台 Red Hat Linux 服务器,无法发送外发电子邮件。我还有一台 Solaris 服务器,之前已配置好将邮件转发到邮件服务器。为了让用户能够从 Red Hat 接收电子邮件,我需要通过 Solaris 服务器转发邮件。我的老板严格要求我使用 Sendmail 而不是 Postfix。
到目前为止,这是我所做的:
solaris 服务器:bres.net.com - 192.65.7.8
红帽:主机名:蝙蝠侠 IP:192.55.7.43
编辑 /etc/mail/sendmail.mc
define(`SMART_HOST',`bres.net.com')dnl
MASQUERADE_AS(`net.com')dnl
FEATURE(masquerade_envelope)dnl
FEATURE(masquerade_entire_domain)dnl
MASQUERADE_DOMAIN(localhost)dnl
MASQUERADE_DOMAIN(localhost.net.com)dnl
MASQUERADE_DOMAIN(batman.net.com)dnl
MASQUERADE_DOMAIN(others.net.com)dnl
编辑 /etc/hosts
127.0.0.1 batman.net.com localhost.localdomain localhost batman
192.55.7.43 batman batman.net.com loghost
192.65.7.8 bres bres.net.com
编辑 /etc/resolv.conf
search net.com
bres.net.com 192.65.7.8
创建新的 sendmail.cf:
m4 sendmail.mc > sendmail.cf
重新启动 sendmail
通过尝试发送邮件进行测试
检查日志 /var/log/maillog
Nov 22 12:00:54 localhost sendmail[22251]: uAM402ru022251: from=root, size=591, class=0, nrcpts=1, msgid=<[email protected]>, relay=root@localhost
Nov 22 12:02:54 localhost sendmail[22281]: uAM40sRm022281: from=<[email protected] >, size=863, class=0, nrcpts=1, msgid=<[email protected]>, proto=ESMTP, daemon=MTA, relay=batman.net.com[127.0.0.1]
Nov 22 12:02:54 localhost sendmail[22251]: uAM402ru022251: to=root, ctladdr=root (0/0), delay=00:02:52, xdelay=00:02:00, mailer=relay, pri=30591, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (uAM40sRm022281 Message accepted for delivery)
Nov 22 12:04:14 localhost sendmail[22303]: uAM40sRm022281: to=<[email protected]>, delay=00:01:20, xdelay=00:01:20, mailer=relay, pri=120863, relay=bres.net.com, dsn=4.0.0, stat=Deferred: Name server: bres.net.com: host name lookup failure
更改define( SMART_HOST',
192.65.7.8')dnl =后,日志显示如下:
Nov 23 09:51:49 batman sendmail[8953]: uAN1m5aZ008953: from=<[email protected]>, size=1052, class=0, nrcpts=1, msgid=<[email protected]>, proto=ESMTP, daemon=MTA, relay=batman.net.com [127.0.0.1]
Nov 23 09:51:49 batman sm-msp-queue[8950]: uAMM02K3007934: to=root, ctladdr=root (0/0), delay=03:51:47, xdelay=00:03:44, mailer=relay, pri=120780, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (uAN1m5aZ008953 Message accepted for delivery)
Nov 23 09:51:49 batman sendmail[8964]: uAN1m5aZ008953: to=<[email protected]>, ctladdr=<[email protected]> (0/0), delay=00:00:00, xdelay=00:00:00, mailer=local, pri=31276, dsn=2.0.0, stat=Sent
Nov 23 09:51:49 batman sendmail[8953]: uAN1m5ab008953: from=<[email protected]>, size=3002, class=0, nrcpts=1, msgid=<[email protected]>, proto=ESMTP, daemon=MTA, relay=batman.net.com [127.0.0.1]
Nov 23 09:51:49 batman sm-msp-queue[8950]: uAMK2UOH007318: to=root, ctladdr=root (0/0), delay=05:49:19, xdelay=00:00:00, mailer=relay, pri=122704, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (uAN1m5ab008953 Message accepted for delivery)
Nov 23 09:51:49 batman sendmail[8966]: uAN1m5ab008953: to=<[email protected]>, ctladdr=<[email protected]> (0/0), delay=00:00:00, xdelay=00:00:00, mailer=local, pri=33231, dsn=2.0.0, stat=Sent
Nov 23 09:54:11 batman sendmail[8962]: uAN1oRWw008962: from=root, size=66, class=0, nrcpts=1, msgid=<[email protected]>, relay=root@localhost
Nov 23 09:54:11 batman sendmail[8962]: uAN1oRWw008962: [email protected], delay=00:03:44, mailer=esmtp, pri=30066, dsn=4.4.3, stat=queued
我可以通过更改定义 SMARTHOST 并在 etc/mail 中添加一个配置文件 (service.switch) 来中继电子邮件。
define(`SMART_HOST',`relay:[192.65.7.8]')dnl
在 etc/mail 添加 service.switch
####### start of file #########
hosts files
aliases files
####### end of file ###########
更改后,邮件中继工作正常。但在 Red Hat 服务器重启后,Sendmail 不工作,日志显示如下:
Nov 25 10:00:30 batman sendmail[15372]: uAP20Ude015372: from=root, size=66,class=0, nrcpts=1, msgid=<[email protected]>, relay=root@localhost
Nov 25 10:00:30 batman sendmail[15372]: uAP20Ude015372: [email protected], ctladdr=root (0/0), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30066,relay=[127.0.0.1] [127.0.0.1], dsn=4.0.0, stat=Deferred: Connection refused by [127.0.0.1]
在此日志之前,日志显示:
Nov 24 10:09:47 batman sendmail[24936]: uAO29kOL024936: ruleset=check_rcpt, arg1=<[email protected]>, relay=[192.65.7.8], reject=450 4.4.0 <[email protected]>... Relaying temporarily denied. Cannot resolve PTR record for 192.65.7.8
日志显示连接被拒绝且无法解析 PTR 记录。请帮忙。
答案1
“主机名查找失败”表示 DNS 错误,不一定是 sendmail 配置错误。
Sendmail,或者更确切地说是发送电子邮件,严重依赖于 DNS,并且不能很好地处理仅作为文件中的条目存在的主机和域/etc/hosts
。
最简单的方法就是确保其nslookup bres.net.com
有效。
也许这是您问题的格式问题,但该条目bres.net.com 192.65.7.8
不属于 a ,并且那里也resolv.conf
应该有一个条目。一个简单的 resolv.conf 如下所示:nameserver <IP-address of nameserver>
#/etc/resolv.conf
domain example.com
search example.com
nameserver 8.8.8.8
options attempts:2
您也可以尝试使用智能主机的 IP 地址而不是主机名,以避免一些 DNS 问题:
define(`SMART_HOST',`[192.65.7.8]')dnl