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進行收發郵件了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM