电子邮件服务器
电子邮件服务器的工作原理
邮件服务器的作用-为一个域收信
chinaitlab.com MX:mail.chinaitlab.com
tom@chinaitlab.com
alice@chinaitlab.com
bob@chinaitlab.com
redhat.org.cn MX:mail.redhat.org.cn
tom@redhat.org.cn
alice@redhat.org.cn
基本概念
发信服务器
用来替用户把邮件发送到目的地的服务器,一般运行着smtp服务器软件。
收信服务器
等待用户来收信的服务器,一般运行着pop/imap服务器软件
通常发信服务器和收信服务器是同一台服务器
client------------------SMTP----------->server---------->POP3/IMAP------------>client
MTA(mail transfer agent)
邮件传输代理。发送邮件服务器的总称,比如sendmail,qmail,postfix,exim等。
MUA(mail user agent)
邮件用户代理。帮助用户收信的客户端软件的总称,比如outlook,mozilla,foxmail等。
MTA: MUA:
Sendmai Outlook
Qmail Foxmail
postfix mozilla
邮件格式
From:tom@chinaitlab.com
Subject:hi
Body:welcome to chinaitlab!
Smtp服务器的工作原理
Sendmail安装与配置
最新版本 sendmail.8.14.3
下载 ftp://ftp.sendmail.org/pub/sendmail/sendmail.8.14.3.tar.gz
准备编译环境
删除sendmail以及postfix
rpm -e – nodeps sendmail
prm -e –nodeps postfix
需要安装cyrus-sasl cyrus-sasl-plain,syrus-sasl-devel,syrus-sasl-gssapi,cyrus-sasl-md5
rpm -qa|grep sasl
首先确认是为那个域
host -t MX chinaitlab.com
host mail.chinaitlab.com
host -t MX redhat.org.cn
host mail.redhat.org.cn
编译安装过程
tar xvzf sendmail.8.13.1.tar.gz
cd sendmail.8.13.1
vi devtools/Site/site.config.m4
APPENDDEF(`confENVDEF',`-DSASL=2')
APPENDDEF(`conf_sendmail_LIBS',`-lsasl2')
sh Build -c
sh Build install
rpm -q m4确认安装了m4宏解释器
mkdir /usr/share/sendmail; cp -a cf /usr/share/sendmail
cd cf/cf
cp generic-linux.mc snedmail.mc
make install-cf ;cp sendmail.mc /etc/mail
cd /etc/mail
touch aliases access
echo "chinaitlab.com" > local-host-names
echo "mail.chinaitlab.com" >> local-host-names
makemap hash access < access
makemap hash aliases < aliases
mkdir /var/spool/mqueue
/usr/sbin/sendmail -bd -q1h
q表示队列1h表示1小时,表示一小时处理一次
ps aux | grep sendmail查看sendmail是否运行成功
POP/IMAP服务器的配置
测试发信
netstat -tnl | grep 25
useradd redhat增加收信账号
passwd redhat
echo "root:redhat">>/etc/mail/aliases
newaliases
telnet localhost 25
mail from: root@chinaitlab.com
rcpt to: redhat@chinaitlab.com
data
hello,mail from smtp command.
.
tail /var/log/maillog
如果可以看到stat=Sent,说明发信成功
邮件客户端的配置
outlook
工具-账户-添加-
显示名 redhat
电子邮件地址redhat@chinaitlab.com
我的邮件接收服务器是imap
接收服务器192.168.0.101
发送服务器192.168.0.101
账户名redhat
密码redhat
rpm -q telnet-server
yum install telnet-server
chkconfig --list | grep telnet
chkconfig telnet on
su - redhat切换到redhat
mail查看收信
起动收信服务器
yum install cyrus-imapd
rpm -ivh /mnt/cdrom/Fedora/RPMS/imap-*.rpm
chkconfig imap on
(或者chkconfig ipop3 on)
ls /etc/xinetd.d
service xinetd restart
grep imap /etc/services
netstat -tnl | grep 143
让fedora支持pop3,imap
yum install dovecot
vi /etc/dovecot.conf
protocols = imap imaps pop3 pop3s
netstat -tnl | grep 143
用outlook收信,使用redhat用户登陆,测试发信给自己
RELAY-转发
netstat -tnl | grep 25
telnet localhost 25
mail from: root@chinaitlab.com
rcpt to:root@redhat.org.cn
data
hello
.
quit
client<---SMTP--->mail.chinaitlab.comt<---SMTP RELAY--->mai.redhat.org.cn
redhat.org.cn MX5 mail.redhat.org.cn
如果需要从服务器转发给互联网用户
此时需要在邮件服务器打开转发
ACCESS
cd /etc/mail
vi sendmail.mc添加
FEATURE(`access_db', `hash -T<TMPF> -o /etc/mail/access.db')dnl
include(`/usr/share/sendmail-cf/m4/cf.m4')dnl 因为是一个宏定义,需要引入默认的宏定义语言
m4 sendmail.mc > sendmail.cf
echo "192.168.0 RELAY" >> access表示允许来自192.168.0.0/24 网段的用户 RELAY
makemap hash access < access
ls -l | grep access可以看到access.db就是刚才用makemap创建出来的
killall sendmail
sendmail -bd -q1h
重新发信给root@redhat.org.cn测式
host -t MX mail.redhat.org.cn
host -t MX mail.chinaitlab.com
host mail.chinaitlab.com
增加用户证
cd /etc/mail
vi sendmail.mc
include(`/usr/share/sendmail/cf/m4/cf.m4')dnl
define(`confAUTH_OPTIONS',`A y')dnl
TRUST_AUTH_MECH(`LOGIN PLAIN')dnl
define(`confAUTH_MECHANISMS',`LOGIN PLAIN')dnl
chkconfig saslauthon
/etc/init.d/saslauthd restart
echo “pwcheck_method:saslauthd”>/usr/lib/sasl2/Sendmail.conf
killall sendmail
/usr/sbin/sendmail -bd -q1h
别名
修改 more /etc/mail/aliases
postmaster:root
daemon:root
bin:root
sys:root
sync:root
games:root
..
root:redhat
..
newaliases
killall sendmail
sendmail -bd -q1h
激活安全的imaps
imaps=imap+ssl(基于SSL的安全imap协议)
chkconfig imap off
chkconfig imaps on
service xinetd restart
netstat -tnl | grep 993
imaps需要客户端MUA软件支持,outlook和mozilla都支持imaps协议
grep imaps /etc/services
参考资料
/usr/share/sendmail/cf/README(来自sendmail的源码)
http://www.sendmail.org/other-sendmail-links.html
新闻组news://comp.mail.sendmail