Thursday, December 14, 2006

尝试将邮件发送到多个smarthost

还没有完全测试,目前的情况来看,还算是成功,明天到实验室试试。

两个smarthost:
  • 实验室内部邮件通过内部的邮件服务器发送
  • 其余非本机邮件通过gmail邮箱发送
嗯,为了这个目的,分析了半天 exim4 的配置文件和手册……邮件服务器没一个简单的……exim 也这么复杂……

简要说一下,其实看明白了配置文件的分块也就差不多知道怎么下手了:配置文件里,一开始是配置、ACL 以及鉴权认证和其他一些设置的内容,至于邮件传送,主要是route和transport两个部分,两者是相对应的。感觉上,route是对进来的邮件进行处理,如果是本地的,就就地分拣、投递,反之,则利用 transport 送到其他主机去,而 smarthost 只是远程发送的一种方式,需要 route 部分看清哪些邮件要送到哪里,然后再在 transport 部分送到相应的主机去,对于 smarthost 这种方式,往往还要对邮件进行发件人的替换。

这个是对 route 部分新添加的(原有的就是 gmail smarthost 的设置),放在 gmail 部分的前面了:


smarthost_cg:
debug_print = "R: smarthost_cg for $local_part@$domain"
driver = manualroute
domains = ! +local_domains : +cg_domains
transport = remote_smtp_smarthost_cg
route_list = * cg.com.cn byname
host_find_failed = defer
same_domain_copy_routing = yes
no_more


关键处被加红了,呵呵。然后在 transport 部分如法炮制

remote_smtp_smarthost_cg:
debug_print = "T: remote_smtp_smarthost_cg for $local_part@$domain"
driver = smtp
hosts_try_auth = ${if exists {CONFDIR/passwd.client}\
{${extract{1}{:}{cg.com.cn}}}\
{}\
}
tls_tempfail_tryclear = false
headers_rewrite = *@+local_domains wangxu@cg.com.cn frs : *@wangxu-doc.cn wangxu@cg.com.cn frs
return_path = ${if match_domain{$sender_address_domain}{+local_domains}{wangxu@cg.com.cn}{${if match_domain{$sender_address_domain}{wangxu-doc.cn}{wangxu@cg.com.cn}fail}}}


headers rewrite 和 return path 部分是根据 /var/lib/exim4/ 中的 exim4 运行时配置文件改写的,呵呵,另外,前面需要定义一个 cg_domains 列表,也就是内部邮件的域名,呵呵。

passwd.client 文件中分别写出两个 smarthost 的用户名和密码,这个就不多说了,提一下,gmail 的应该写 gmail-smtp.l.google.com , 虽然有点跑题,但也算是有点用吧,呵呵。

嗯,上述内容测试还不完整,待完整后补充、发布到主页吧,呵呵,目前发送到 gmail 是正常的,发送到内部邮件系统的会去尝试内部邮件系统,不过,无奈,当前我没有接在局域网上,日志中显示是连接超时,貌似正常,呵呵,待明天一试。

No comments: