postfix+dovecot配置多域名邮件服务器

mail邮局系统的MX(邮件交换)记录配置,以便收发邮件。(MX记录,是邮件交换记录,它指向一个邮件服务器,用于电子邮件系统发邮件时根据收信人的地址后缀来定位邮件服务器,如果没有做域名解析,邮局不能正常使用,即不能正常的发送或者接收邮件。)

一、安装postfixdovecot

yum install postfix dovecot
chkconfig postfix on
chkconfig dovecot on

也可以用一次安装所有依赖包 yum install sysstat   postfix   crontabs redhat-lsb-graphics   redhat-lsb-core   arpwatch  cronie dovecot

1、配置postfix

vi /etc/postfix/main.cf

# change or add on these line:

myhostname = yes81.net

mydomain = yes81.net

myorigin = $mydomain

inet_interfaces = all

mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain

mynetworks = 127.0.0.0/8

home_mailbox = Maildir/

 

smtpd_sasl_type = dovecot

smtpd_sasl_path = private/auth

smtpd_sasl_auth_enable = yes

smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination, permit

broken_sasl_auth_clients = yes

2dovecot配置

vi /etc/dovecot/dovecot.conf

# uncomment on this line:

protocols = imap pop3

listen = *

3、配置认证方式

vi /etc/dovecot/conf.d/10-auth.conf

# change on these line:

disable_plaintext_auth = no

auth_mechanisms = plain login

4、设置邮箱文件夹

vi /etc/dovecot/conf.d/10-mail.conf

mail_location = maildir:~/Maildir

5、配置认证

vi /etc/dovecot/conf.d/10-master.conf

# commented on these line:

#unix_listener auth-userdb {

    #mode = 0600

    #user =

    #group =

  #}

 

# change or setup on these line:

# Postfix smtp-auth

  unix_listener /var/spool/postfix/private/auth {

    mode = 0666

    user = postfix

    group = postfix

  }

6、配置pop3

vi /etc/dovecot/conf.d/20-pop3.conf

# uncomment on these line:

pop3_uidl_format = %08Xu%08Xv

pop3_client_workarounds = outlook-no-nuls oe-ns-eoh

7、重启dovecot postfix

Service dovecot restart

Service postfix restart

 

8、增加用户和设置用户密码

 这个时候就可以增加用户和设置用户密码,然后测试收发

groupadd mailuser

adduser -g mailuser -s /sbin/nologin test1

passwd  test1

adduser -g mailuser -s /sbin/nologin test2

passwd  test2

打开FOXMAIL等邮件工具测试,能正常收发,就表示系统可以了。

test1@mail.yes81.net  test2@mail.yes81.net

 

二、 如果无法发信

试着发送邮件,如果发送不出去,查看日志文件/var/log/maillog 如果显示:

postfix/smtp[17105]: fatal: unknown service: smtp/tcp

postfix/smtpd: disconnect from unknown[113.64.242.145]

postfix/qmgr: warning: private/smtp socket: malformed response

postfix/qmgr: warning: transport smtp failure -- see a previous warning/fatal/panic logfile record for the problem description

postfix/master: warning: process /usr/libexec/postfix/smtp pid 17105 exit status 1

postfix/master: warning: /usr/libexec/postfix/smtp: bad command startup -- throttling

这是由于邮件默认的postfix账号无法执行/etc/services,权限不足所致。查看service的权限为640:

 Chmod 644 /etc/services   于是将其改为644:

 重新启动2个服务后就可以看到,一切正常了!

 

三、如何添加虚拟域名:

http://www.postfix.org/VIRTUAL_README.html

按照官方指导,对于多域名的支持postfix支持以下几种方式:

1.共享域名,共享Unix账户

2.虚拟别名(Virtual Alias)独立域名,共享Unix账户

3.虚拟邮箱(Virtual Mailbox)独立域名,无需Unix账户

4.转发服务器(Forwarding Server)用做备份服务器,主服务器故障时暂存邮件,恢复后直接转发给主服务器

 

从官网查到后,决定采用第2种方法:虚拟别名(Virtual Alias)独立域名,共享Unix账户

vi /etc/postfix/main.cf 
     virtual_alias_domains = t3t3.org
      virtual_alias_maps = hash:/etc/postfix/virtual
      alias_maps=hash:/etc/aliases
 
vi /etc/postfix/virtual
      test1@t3t3.org  test1
     test2@t3t3.org  test2
     test1@yes81.net  test1
     test2@yes81.net  test2
vi /etc/aliases  //把刚添加的帐号做个别名
test1:     test1
test2:     test2
 

postmap /etc/postfix/virtual   //reload 数据库后需新域名就可以使用了

postalias /etc/aliases   //   postfix  /etc/aliases命令是否等同?

newaliases

postfix  reload       //reload

Service dovecot restart  //重新启动

Service postfix restart  //重新启动

 

如果操作postfix  /etc/aliases时候出现/usr/libexec/postfix/postfix-script: line 337: /etc/aliases: Permission denied则需要修改权限:

chmod 664 /etc/aliases

chown root /etc/aliases

chmod 755 /etc/aliases.db

chown smmsp /etc/aliases.db

修改好权限后,再次执行reload和重新等命令

 

如此后邮件服务器就可以用test1@yes81.net   test1@t3t3.org进行收发邮件了。

posted @ 2015-03-24 15:15  Fatt  阅读(4962)  评论(0编辑  收藏  举报