/ 中存储网

教你如何在CentOS 5.9系统中安装配置sendmail邮件服务器

2014-11-09 00:48:12 来源:中存储网

教你如何在CentOS 5.9系统中安装配置sendmail邮件服务器

sendmail所需包只需两个:
# rpm -qa |grep sendmail
sendmail-8.13.8-2.el5
sendmail-cf-8.13.8-2.el5


安装sendmail做smtp SERVER
步骤一:Sendmail前先做DNS 配置 定义主域名
这一步是配置DNS服务器
# cat /etc/named.conf
zone "mydomain.com" IN {
        type master;
        file "mydomain.zone";
        allow-update { none; };
};
vi /var/named/mydomain.zone $TTL    86400
              IN SOA       root (
                                        42              ; serial (d. adams)
                                        3H              ; refresh
                                        15M             ; retry
                                        1W              ; expiry
                                        1D );
@ IN NS         192.168.0.12;
  IN A          192.168.0.12;
www IN A 192.168.0.12;
test IN A 192.168.0.12;
ftp IN A 192.168.0.12;  
pop3 IN A 192.168.0.12;
smtp IN A 192.168.0.1

步骤二:sendmail.cf修改
 使本地和异地foxmail都能发mail
必须改成实际域名,否则虽然 linux本地能发mail,但一些客户端(如foxmail)无法通过sendmail发mail
C{w}localhost localdomain
改成
C{w}localhost    mydomain.com  smtp.mydomain.com
                    主域名      email(smtp)服务器域名
=========================================
# SMTP client options
#O ClientPortOptions=Family=inet, Address=0.0.0.0
client address不必改,就保持缺省的#
=========================================
# SMTP daemon options
O DaemonPortOptions=Port=smtp,Addr=0.0.0.0, Name=MTA   
Addr只能是0.0.0.0
 
步骤三:linux smtp服务启动
# /etc/init.d/sendmail restart
Shutting down sendmail: [  OK  ]
Shutting down sm-client: [  OK  ]
Starting sendmail: [  OK  ]
Starting sm-client: [  OK  
sendmail daemon启动同时也启动了client


步骤四:email客户端PC配置
1. PC  DNS指向上面的DNS SERVER
 
2. pop3 帐户就是unix 普通用户
pop3 account:mac
pop3 password:xxxxxx
3. foxmail 建立帐户
帐户mac@mydomain.com
SMTP SERVER :smtp.mydomain.com
POP3 SERVER :pop3.mydomain.com
 ========================
#groupadd mailuser
#useradd -g mailuser mac -s /sbin/nologin
/etc/mail/access不必做任何修改
vi access
localhost.localdomain           RELAY
localhost                       RELAY
127.0.0.1                       RELAY
mydomain.com                    RELAY
smtp.mydomain.com               RELAY
192.168.0          RELAY
 
删掉了192.168.0          RELAY
FOXMAIL仍能发mail
本机也能发mail给本机帐户
删掉mydomain.com                        RELAY
删掉smtp.mydomain.com                   RELAY
FOXMAIL仍能发mail
本机也能发mail给本机帐户
总之,/etc/mail/access不必做任何修改
注意修/etc/mail/改access,完后都要做两步:
# makemap hash /etc/mail/access.db < /etc/mail/access
# /etc/init.d/sendmail restart
    local-host-names不必做任何修改
# cat local-host-names
# local-host-names - include all aliases for your machine here.
 
FOXMAIL仍能发mail
本机也能发mail给本机帐户
 
    sendmail.cf是sendmail的主配置文件
    早期sendmail.cf是放在/etc下
            RH9是放在/etc/mail下
    在src/sendmail.x.x.x/cf目录下还有许多适应各种系统的sendmail.cf的文件样本
======================================================
    两种sendmail.cf配置方法
直接修改 /etc/mail/sendmail.cf文件来配置sendmail的
mc生成法:配置sendmail.mc文件,生成sendmail.cf
只是在做身份验证的时候才使用sendmail.mc文件
vi /etc/mail/sendmial.mc
m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf 
 
    sendmail.cf 下的DaemonPortOptions=Port=smtp,Addr的设法
# SMTP daemon options
O DaemonPortOptions=Port=smtp,Addr=127.0.0.1, Name=MTA  
此时可以在本地给本机发mail
但在其他PC无法用foxmail通过 sendmail发邮件
 
# SMTP daemon options
O DaemonPortOptions=Port=smtp,Addr=192.168.1.12, Name=MTA
此时linux本地无法通过mail指令发mail给本机用户
但可以在其他PC用foxmail 通过sendmail 发邮件
 
# SMTP daemon options
O DaemonPortOptions=Port=smtp,Addr=0.0.0.0, Name=MTA  
最佳办法
既可以在本地给本机发mail
也可以在PC用foxmail发
 
    mail troubleshooting 能发信不能收信
    sendmail 通,pop3(dovecot)没通
能本地发信给本地帐户,但不能通过异地客户端(foxmail)发信的 
  sendmail.cf中 option address 设成127.0.0.1了,改成0.0.0.0
能通过异地客户端(foxmail)发信的,而不能本地发信给本地帐户   
  sendmail.cf中 option address 设成具体地址了,改成0.0.0.0
也可能出现foxmail可以发信给SERVER的另一个帐户,实际仍属于server本地发信,但无法发信给一个mail server的帐户  
 foxmail 的smtp server 要设“authentication "---"use same account and password as pop3"

dovecot pop3 imap邮服务
#yum install dovecot
#chkconfig add dovecot
#service dovecot start
 
  其他配置文件
# ls /etc/mail
access     domaintable     helpfile          mailertable     Makefile     sendmail.mc   submit.cf  trusted-users  virtusertable.db
access.db  domaintable.db  local-host-names  mailertable.db  sendmail.cf  spamassassin  submit.mc  virtusertable
 
# cat  local-host-names
====================================
# local-host-names - include all aliases for your machine here
 
# cat trusted-users
====================================
# trusted-users - users that can send mail as others without a warning
# apache, mailman, majordomo, uucp, are good candidates
 
# cat access
====================================
# Check the /usr/share/doc/sendmail/README.cf file for a description
# of the format of this file. (search for access_db in that file)
# The /usr/share/doc/sendmail/README.cf is part of the sendmail-doc
# package.
#
# by default we allow relaying from localhost...
localhost.localdomain           RELAY
localhost                       RELAY
127.0.0.1                       RELAY
192.168.0                       RELAY

      sendmail log在哪里看?
# cat /var/log/maillog
================================== May  7 18:01:55 localhost pop3-login: Login: macg [::ffff:192.168.1.11]
May  7 18:05:08 localhost sendmail[6566]: l47A48Iq006566: from=<macg@192.168.1.12>, size=328, class=0, nrcpts=1, msgid=<200705071005.l47A48Iq006566@localhost.localdomain>, proto=SMTP, daemon=MTA, relay=[192.168.1.11]
May  7 18:05:08 localhost sendmail[6566]: l47A48Iq006566: to=<macg@192.168.1.12>, delay=00:00:00, mailer=esmtp, pri=30328, dsn=4.4.3, stat=queued