网页浏览总次数

2011年3月5日星期六

CentOS 5 配置 sendmail 用户转发

如果以用户 A 的身份给用户 B 发送信件,但用户 B 不可达,则 sendmail 会尝试给 A 发退信通知,如果 A 也不可达则会堵住邮件队列。这种情况通常发生在需要发送匿名邮件时,A通常是个伪帐号。

解决办法是把发给A的信件转给一个可达的地址,比如C,在sendmail可通过如下方式实现:

方案一:配置别名(alias),A的别名是C
方案二:通过虚拟帐号(virtusertable)
方案三:通过地址改写

在 O'Reilly Sendmail 4th Edition 这本书有这么一段文字描述

Before undertaking this step, however, see §17.8.59 on page 645 for a description of the FEATURE(virtusertable) which also allows nonlocal addresses to be transformed into inside or outside addresses. Note, too, that the User Database (§23.7.27 on page 942) allows recipient addresses to be changed so that they can be delivered to new hosts, and that the FEATURE(genericstable) in §17.8.19 on page 622 allows sender addresses to be changed to appear to be coming from new hosts. Clearly, there are many ways to achieve the same result, and one of those might be more suitable to your needs than the F=A flag.

方案一和二默认只支持本地域,如果A不属于本地域,则需要做额外的配置。假设本地域是 localdomain,而A的地址是 user-a@example.com,则方案二的实现过程如下:

修改 /etc/mail/sendmail.mc,确认如下行以配置

...
FEATURE(`virtusertable', `hash -o /etc/mail/virtusertable.db')dnl
...
VIRTUSER_DOMAIN(`example.com')
...

修改 /etc/mail/virtusertable,如下
user-a@example.com another-user@another-domain

如果another-user是本地域的用户,则 @another-domain 可以省略。

执行如下命令让配置生效

cd /etc/mail
make
makemap hash /etc/mail/virtusertable.db < /etc/mail/virtusertable
/etc/init.d/sendmail restart

要flush特定特征的队列里的邮件,比如收件人地址含 leo 的邮件,可用

/usr/sbin/sendmail -qf -qRleo -v

参考 http://kb.bobcares.com/?View=entry&EntryID=153

没有评论:

发表评论