[root@ding ~]# rpm -qa | grep sendmailsendmail-cf-8.13.8-8.1.el5_7sendmail-8.13.8-8.1.el5_7[root@ding ~]# rpm -qa | grep m4m4-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 restartShutting down sm-client: [ OK ]Shutting down sendmail: [ OK ]Starting sendmail: [ OK ]Starting sm-client: [ OK ][root@ding ~]# service saslauthd restartStopping saslauthd: [ OK ]Starting saslauthd: [ OK ][root@ding ~]# netstat -ntl | grep 25tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN
配置dovecot
[root@ding ~]# rpm -qa | grep dovecotdovecot-1.0.7-8.el5_9.1[root@ding ~]# vi /etc/dovecot.conf 20 protocols = imap imaps pop3 pop3s[root@ding ~]# service dovecot restartStopping Dovecot Imap: [ OK ]Starting Dovecot Imap: [ OK ] [root@ding ~]# netstat -ntl | grep 143tcp 0 0 :::143 :::* LISTEN
配置foxmail客户端
Email Adress: dh@dingpasssword: ********Receiver type: pop3Account: dhpassword: ********IMAP server: mail.dingSMTP server: mail.ding
mail.ding邮箱自发自收成功
[root@ding ~]# mail -s "hello" dh@mail.dinghi,I am ding..Cc: tail -F /var/log/maillogJan 1 17:25:08 ding sendmail[11012]: t021P8LM011012: from=root, size=44, class=0, nrcpts=1, msgid=<201501020125.t021P8LM011012@ding.net>, relay=root@localhostJan 1 17:25:08 ding sendmail[11013]: t021P8cw011013: from=, 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 directoryJan 1 17:25:08 ding sendmail[11014]: t021P8cw011013: forward /home/dh/.forward: World writable directoryJan 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= , 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.pemumask 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 $PEM2Generating 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 incorporatedinto 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 blankFor 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) []:qaCommon Name (eg, your name or your server's hostname) []:hdingEmail Address []:dh@mail.hding[root@hding certs]# vi /etc/mail/sendmail.mc134 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 restartShutting 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 restartStopping 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/256Jan 9 16:06:10 hding sendmail[7151]: AUTH=server, relay=[192.168.0.101], authid=dh@hding, mech=LOGIN, bits=0Jan 9 16:06:10 hding sendmail[7151]: t0A0696o007151: from=, 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= , ctladdr= (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/256Jan 9 16:09:43 hding sendmail[7160]: t0A09hjW007160: from= , 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 directoryJan 9 16:09:43 hding sendmail[7161]: t0A09hjW007160: forward /home/dh/.forward: World writable directoryJan 9 16:09:43 hding sendmail[7161]: t0A09hjW007160: to= , delay=00:00:00, xdelay=00:00:00, mailer=local, pri=31634, dsn=2.0.0, stat=SentJan 9 16:10:03 hding dovecot: pop3-login: Aborted login: user= , method=PLAIN, rip=::ffff:192.168.0.101, lip=::ffff:192.168.0.111, TLSJan 9 16:10:03 hding dovecot: pop3-login: Login: user= , method=PLAIN, rip=::ffff:192.168.0.101, lip=::ffff:192.168.0.111, TLSJan 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=, ctladdr= (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 errorhosts中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=, ctladdr= (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/hostsvi /etc/sysconfig/networkhostname
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=, ctladdr= (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=, ctladdr= (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 MTAMTA已经是ding,主机名却是ding.terry.com
目前两台server总算工作正常,中间也在网上找了很多资料,好不容易搞能了,希望能帮助其它人早日找到解决问题的办法