关于我
 

xjpvictor's Blog
小老鼠,上灯台,两只耳朵竖起来

vps邮件服务器 (6)


各种折腾·emaillinuxvps

本文最后编辑于超过2826天以前,部分内容可能已经失效

折腾无止境,继续优化邮件服务器。

这次是添加多个域名。和上一篇不一样的是,上次是其他邮件提供商,比如gmail,而这次是自己服务器提供不同域名的邮件收发。

其实需要设置的不多,也不复杂。根据第一篇设置virtual_mailboxesvirtual_aliasvirtual_domains,记得postmap。然后设置dovecot的dovecot-user。之后重启postfixdovecot服务就行。

如果需要对发出的邮件进行spf验证,就去dns设置相应的TXT记录。类似postfix的sender_bcc,dovecot的sieve规则都可以参考之前的文章进行设置。自己架设邮箱有个好处就是如果换邮箱的话,只需要把保存邮件的目录名改成新邮箱地址就行,旧的邮件和sieve规则都在。

唯一有些不同的是dkim的设置。

之前的/etc/opendkim/opendkim.conf内的设置是

Domain                  example.com
KeyFile                 /etc/opendkim/default.private
Selector                dkim
Socket                  inet:8891@localhost
UserID                  opendkim

为了对不同的域名签名,必须改成

Socket                  inet:8891@localhost
UserID                  opendkim

KeyTable                /etc/opendkim/KeyTable
SigningTable            refile:/etc/opendkim/SigningTable
ExternalIgnoreList      refile:/etc/opendkim/TrustedHosts
InternalHosts           refile:/etc/opendkim/TrustedHosts

发现了吗,domainkeyfile都没有了。因为不同的域名要用不同的key,即使用同一个key,也不能设置,因为domain仍然不同。

修改后opendkim会依据/etc/opendkim/KeyTable/etc/opendkim/SigningTable使用签名密钥对发出邮件进行签名。

/etc/opendkim/KeyTable的内容是

dkim._domainkey.example1.com example1.com:dkim:/etc/opendkim/example1.com.key
dkim._domainkey.example2.com example2.com:dkim:/etc/opendkim/example2.com.key

/etc/opendkim/SigningTable的内容是

*@example1.com dkim._domainkey.example1.com
*@example2.com dkim._domainkey.example2.com

/etc/opendkim/TrustedHosts内写上所有的域名

example1.com
example2.com

之后执行opendkim-genkey -r -s dkim -d example1.com获得密钥和公钥。把密钥保存到/etc/opendkim/example1.com.key,把公钥放去dns的TXT记录里,重启opendkim就可以了。

可以向gmail发封邮件,测试一下。

注意一下,我所有的selector都用了dkim,在KeyTableSigningTable和生成密钥公钥时候都用了这个selector,同样的dns中也是用了这个selector,TXT的名字是dkim._domainkey,如果想用不同的selector就可以修改相应的文件。

本文 "vps邮件服务器 (6)" 由 K. Huang 首先发表于 xjpvictor's Blog 并以 CC BY-NC 4.0 许可证发布 © 2016
转载注明引用来源 https://blog.xjpvictor.info/2016/07/email-server-6/


推广:本博客使用 Linode VPS,口碑好,信誉佳,快速稳定,性价比高

打赏我

评论

你的邮箱地址不会被公开。必填项以 * 标出

无意义或不相关评论将被删除

允许使用以下html标签:<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

你可以上传文件,粘贴代码或长文至 Drop.it.r

本博客是言论不自由博客,评论只接受询问及赞同,不同观点请出门左转微博/发表于自己的博客。谢谢合作!

评论意味着你 同意 上传部分私人数据,包括邮箱和 IP, 这些数据不会被分享给第三方,不会用于商业用途或再推广用途。

更多相似文章