Linux_Mail_Server

mail服务器分为发邮件和收邮件,发邮件主要由sendmail来完成,收邮件主要由dovecot来完成,当然也有其它的软件,该文介绍sendmail+dovecot=mail服务器的架设。
配置mail服务器所需软件
[root@ding ~]# rpm -qa | grep sendmail
sendmail-cf-8.13.8-8.1.el5_7
sendmail-8.13.8-8.1.el5_7
[root@ding ~]# rpm -qa | grep m4
m4-1.4.5-3.el5.1

配置主配置文件

[root@ding ~]# vi /etc/mail/sendmail.mc
 52 TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl                 开启认证        
 53 define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLA
    IN')dnl 
116 DAEMON_OPTIONS(`Port=smtp,Addr=0.0.0.0, Name=MTA')dnl                       修改为全网段监听

写进真正的配置文件

[root@ding ~]# m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf

配置短域名

[root@ding ~]# vi /etc/mail/local-host-names 

  1 # local-host-names - include all aliases for your machine here.
  2 ding
  3 mail.ding

启动sendmail

[root@ding ~]# service sendmail restart
Shutting down sm-client: [  OK  ]
Shutting down sendmail: [  OK  ]
Starting sendmail: [  OK  ]
Starting sm-client: [  OK  ]
[root@ding ~]# service saslauthd restart
Stopping saslauthd:                                        [  OK  ]
Starting saslauthd:                                        [  OK  ]
[root@ding ~]# netstat -ntl | grep 25
tcp        0      0 0.0.0.0:25                  0.0.0.0:*                   LISTEN

配置dovecot

[root@ding ~]# rpm -qa | grep dovecot
dovecot-1.0.7-8.el5_9.1
[root@ding ~]# vi /etc/dovecot.conf 
  20 protocols = imap imaps pop3 pop3s
[root@ding ~]# service dovecot restart
Stopping Dovecot Imap:                                     [  OK  ]
Starting Dovecot Imap:                                     [  OK  ] 
[root@ding ~]# netstat -ntl | grep 143
tcp        0      0 :::143                      :::*                        LISTEN

配置foxmail客户端

Email Adress: dh@ding
passsword:   ********
Receiver type: pop3
Account:      dh
password:    ********
IMAP server: mail.ding
SMTP server: mail.ding

mail.ding邮箱自发自收成功

[root@ding ~]# mail -s "hello" dh@mail.ding
hi,
I am ding.
.
Cc: 
tail -F /var/log/maillog
Jan  1 17:25:08 ding sendmail[11012]: t021P8LM011012: from=root, size=44, class=0, nrcpts=1, msgid=<201501020125.t021P8LM011012@ding.net>, relay=root@localhost
Jan  1 17:25:08 ding sendmail[11013]: t021P8cw011013: from=<root@ding.net>, size=295, class=0, nrcpts=1, msgid=<201501020125.t021P8LM011012@ding.net>, proto=ESMTP, daemon=MTA, relay=ding [127.0.0.1]
Jan  1 17:25:08 ding sendmail[11014]: t021P8cw011013: forward /home/dh/.forward.localhost: World writable directory
Jan  1 17:25:08 ding sendmail[11014]: t021P8cw011013: forward /home/dh/.forward: World writable directory
Jan  1 17:25:08 ding sendmail[11012]: t021P8LM011012: to=dh@mail.ding, ctladdr=root (0/0), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30044, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (t021P8cw011013 Message accepted for delivery)
Jan  1 17:25:08 ding sendmail[11014]: t021P8cw011013: to=<dh@mail.ding>, delay=00:00:00, xdelay=00:00:00, mailer=local, pri=30471, dsn=2.0.0, stat=Sent

ding sendmail server(192.168.0.114)和 hding sendmail server(192.168.0.111)互发邮件: XP(192.168.0.101)用foxmail作为客户端:

分析:两台server分别有自己的DNS server,分别有自己的sendmail server,即它们是互相独立的,如何能让对方认出自己,给自己发邮件,需要DNS互相解析,其中这边应用的是forward DNS

[root@hding ~]# vi /etc/named.conf 
 26 zone "ding" {                                             
 27     type forward;                                         
 28     forwarders {192.168.0.114;};                          
 29 }; 
[root@ding ~]# vi /etc/named.conf 
 27 zone "hding" {
 28     type forward;
 29     forwarders {192.168.0.111;};
 30 };

客户端也需要能解析这两边的地址,所以只需要指向他们其中的一个作为DNS server则能全部解析出来

mail over ssl
[root@hding ~]# cd /etc/pki/tls/certs/
[root@hding certs]# make sendmail.pem
umask 77 ; \
        PEM1=`/bin/mktemp /tmp/openssl.XXXXXX` ; \
        PEM2=`/bin/mktemp /tmp/openssl.XXXXXX` ; \
        /usr/bin/openssl req -utf8 -newkey rsa:2048 -keyout $PEM1 -nodes -x509 -days 365 -out $PEM2 -set_serial 0 ; \
        cat $PEM1 >  sendmail.pem ; \
        echo ""    >> sendmail.pem ; \
        cat $PEM2 >> sendmail.pem ; \
        rm -f $PEM1 $PEM2
Generating a 2048 bit RSA private key
................................+++
....................+++
writing new private key to '/tmp/openssl.pw7007'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [GB]:
State or Province Name (full name) [Berkshire]:
Locality Name (eg, city) [Newbury]:
Organization Name (eg, company) [My Company Ltd]:
Organizational Unit Name (eg, section) []:qa
Common Name (eg, your name or your server's hostname) []:hding
Email Address []:dh@mail.hding
[root@hding certs]# vi /etc/mail/sendmail.mc
134 DAEMON_OPTIONS(`Port=smtps, Name=TLSMTA, M=s')dnl
 60 define(`confCACERT_PATH', `/etc/pki/tls/certs')dnl
 61 define(`confCACERT', `/etc/pki/tls/certs/ca-bundle.crt')dnl
 62 define(`confSERVER_CERT', `/etc/pki/tls/certs/sendmail.pem')dnl
 63 define(`confSERVER_KEY', `/etc/pki/tls/certs/sendmail.pem')dnl
[root@hding certs]# m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
[root@hding certs]# service sendmail restart
Shutting down sm-client: [  OK  ]
Shutting down sendmail: [  OK  ]
Starting sendmail: [  OK  ]
Starting sm-client: [  OK  ]
[root@hding certs]# vi /etc/dovecot.conf 
  85 ssl_disable = no
  91 ssl_cert_file = /etc/pki/dovecot/certs/dovecot.pem
  92 ssl_key_file = /etc/pki/dovecot/private/dovecot.pem
[root@hding certs]# service dovecot restart
Stopping Dovecot Imap: [  OK  ]
Starting Dovecot Imap: [  OK  ]
[root@hding certs]# netstat -ntlp 
tcp        0      0 0.0.0.0:465                 0.0.0.0:*                   LISTEN      7063/sendmail: acce 
tcp        0      0 :::995                      :::*                        LISTEN      7097/dovecot


sendmail log:
Jan  9 16:06:09 hding sendmail[7151]: STARTTLS=server, relay=[192.168.0.101], version=TLSv1/SSLv3, verify=NO, cipher=DHE-RSA-AES256-SHA, bits=256/256
Jan  9 16:06:10 hding sendmail[7151]: AUTH=server, relay=[192.168.0.101], authid=dh@hding, mech=LOGIN, bits=0
Jan  9 16:06:10 hding sendmail[7151]: t0A0696o007151: from=<dh@hding>, size=1237, class=0, nrcpts=1, msgid=<2015011822462078142417@hding>, proto=ESMTP, daemon=TLSMTA, relay=[192.168.0.101]
Jan  9 16:06:23 hding sendmail[7153]: t0A0696o007151: to=<dh@mail.ding>, ctladdr=<dh@hding> (501/501), delay=00:00:13, xdelay=00:00:13, mailer=esmtp, pri=121237, relay=mail.ding. [192.168.0.114], dsn=2.0.0, stat=Sent (t0226na6011114 Message accepted for delivery)
dovecot log:
Jan  9 16:09:43 hding sendmail[7160]: STARTTLS=server, relay=[192.168.0.114], version=TLSv1/SSLv3, verify=NO, cipher=DHE-RSA-AES256-SHA, bits=256/256
Jan  9 16:09:43 hding sendmail[7160]: t0A09hjW007160: from=<dh@ding.net>, size=1395, class=0, nrcpts=1, msgid=<2015011822495417159318@ding>, proto=ESMTP, daemon=MTA, relay=[192.168.0.114]
Jan  9 16:09:43 hding sendmail[7161]: t0A09hjW007160: forward /home/dh/.forward.hding: World writable directory
Jan  9 16:09:43 hding sendmail[7161]: t0A09hjW007160: forward /home/dh/.forward: World writable directory
Jan  9 16:09:43 hding sendmail[7161]: t0A09hjW007160: to=<dh@mail.hding>, delay=00:00:00, xdelay=00:00:00, mailer=local, pri=31634, dsn=2.0.0, stat=Sent
Jan  9 16:10:03 hding dovecot: pop3-login: Aborted login: user=<dh@hding>, method=PLAIN, rip=::ffff:192.168.0.101, lip=::ffff:192.168.0.111, TLS
Jan  9 16:10:03 hding dovecot: pop3-login: Login: user=<dh>, method=PLAIN, rip=::ffff:192.168.0.101, lip=::ffff:192.168.0.111, TLS
Jan  9 16:10:03 hding dovecot: POP3(dh): Disconnected: Logged out top=0/0, retr=1/1717, del=0/15, size=31636

这次server的搭建过程中遇到的问题,总结如下:

1 foxmail中不让用mail.ding作为域名解析, 原因不是因为寻找不到主机,而是因为我把client相应的DNS设置成备用的,设置成主用即可


2 foxmail中设置pop3与imap的方式不同,pop3设置账号需要邮件全名dh@xxx, IMAP却不能写全名,只能写dh而无需@xxx


3 Dec 31 19:53:45 ding sendmail[7647]: t013rjmj007645: to=<dh@mail.hding>, ctladdr=<dh@ding> (501/501), delay=00:00:00, xdelay=00:00:00, mailer=esmtp, pri=121182, relay=mail.hding. [192.168.0.111], dsn=5.6.0, stat=Data format error
hosts中127.0.0.1中的主机名要排在第一个,比localhost前
[root@ding mail]# vi /etc/hosts

  1 # Do not remove the following line, or various programs
  2 # that require network functionality will fail.
  3 127.0.0.1      ding ding.net
  4 ::1     localhost6.localdomain6 localhost6


4 Jan  8 16:53:37 localhost sendmail[6444]: t090rb5Q006442: SYSERR(root): ding.localdomain. config error: mail loops back to me (MX problem?)
Jan  8 16:53:37 localhost sendmail[6444]: t090rb5Q006442: to=<dh@ding.localdomain>, ctladdr=<root@localhost.localdomain> (0/0), delay=00:00:00, xdelay=00:00:00, mailer=esmtp, pri=120325, relay=ding.localdomain. [192.168.0.114], dsn=5.3.5, stat=Local configuration error
日志看出是localdomain发出来的,显然主机名不对,设置完主机名后需要重启
vi /etc/hosts
vi /etc/sysconfig/network
hostname


5 Jan  8 17:08:03 localhost sendmail[6491]: t09180FI006491: to=dh@ding, ctladdr=root (0/0), delay=00:00:03, xdelay=00:00:03, mailer=relay, pri=30031, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (t09180Fo006492 Message accepted for delivery)
Jan  8 17:08:25 localhost sendmail[6494]: t09180Fo006492: to=<dh@ding.com>, ctladdr=<root@hding.com> (0/0), delay=00:00:22, xdelay=00:00:22, mailer=esmtp, pri=120284, relay=ding-com.mail.protection.outlook.com. [213.199.154.23], dsn=5.7.1, stat=User unknown
不能发@ding, 必需是mail.ding


6 Jan  8 16:46:02 localhost sendmail[6394]: t090k2uo006392: to=<dh@ding>, ctladdr=<root@localhost.localdomain> (0/0), delay=00:00:00, xdelay=00:00:00, mailer=esmtp, pri=120313, relay=ding, dsn=5.1.2, stat=Host unknown (Name server: ding: host not found)
本地DNS不能解析对方的server,所以在发之前先用nslookup看看


7 Jan  8 10:55:04 localhost sendmail[5549]: t08It4xn005549: ding.terry.com [192.168.0.114] did not issue MAIL/EXPN/VRFY/ETRN during connection to MTA
MTA已经是ding,主机名却是ding.terry.com

目前两台server总算工作正常,中间也在网上找了很多资料,好不容易搞能了,希望能帮助其它人早日找到解决问题的办法









转载于:https://my.oschina.net/hding/blog/369143

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值