- 创建用户 [root@ebs-51660 ~]# useradd admin 你的邮箱用户名 [root@ebs-51660 ~]# echo "123456" | passwd admin --stdin
- 确认MX记录的添加是否生效 [root@ebs-51660 ~]# host fshongling.com fshongling.com mail is handled by 10 mail.fshongling.com.
- 安装postfix [root@ebs-51660 ~]# yum install postfix
- 删除sendmail [root@ebs-51660 ~]# rpm -e sendmail
- 更改默认邮件传输代理 [root@ebs-51660 sasl2]# alternatives --config mta 选择 命令 ----------------------------------------------- *+ 1 /usr/sbin/sendmail.postfix 按 Enter 来保存当前选择[+],或键入选择号码:1
- 查看postfix [root@ebs-51660 ~]# alternatives --display mta
- postfix主配置文件main.cf [root@ebs-51660 postfix]# vim /etc/postfix/main.cf a、myhostname = mail.fshongling.com //76行,将等号后面的部分改写为本机主机名 b、mydomain = fshongling.com //82行,设置域名 c、myorigin = $mydomain //97行,把$myhostname改为$mydomain d、inet_interfaces = all //112行,把后面的localhost改成all e、mydestination = $myhostname, localhost.$mydomain, localhost,$mydomain // 163行,把前面的注释拿掉,并加一下$mydomain f、mynetworks = 192.168.0.0/24, 127.0.0.0/8 //263行,设置内网和本地IP g、local_recipient_maps = //209行,把前面的注释拿掉。h、smtpd_banner = $myhostname ESMTP unknow //568行,把前面的注释拿掉,然后把$mail_name ($mail_version)改成unknow h、//在main.cf文件的底部加上以下内容 l、smtpd_sasl_auth_enable = yes //使用SMTP认证 m、broken_sasl_auth_clients = yes //让不支持RFC2554的smtpclient也可以跟postfix做交互。 n、smtpd_sasl_local_domain = $myhostname // 指定SMTP认证的本地域名 o、smtpd_sasl_security_options = noanonymous //取消匿名登陆方式p、smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination //设定邮件中有关收件人部分的限制 q、 smtpd_sasl_security_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination //设置允许范围 r、message_size_limit = 15728640 //邮件大小 s、mailbox_transport=lmtp:unix:/var/lib/imap/socket/lmtp //设置连接cyrus-imapd的路径 完成后,使用/usr/sbin/postconf -n来检查配置是否正确
-
配置SELinux
查看是否安装SELinux [root@ebs-51660 ~]# cat /etc/sysconfig/selinux # This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing -SELinux security policy is enforced. # permissive -SELinux prints warnings instead of enforcing. # disabled -No SELinux policy is loaded.SELINUX=enforcing # SELINUXTYPE= type of policy in use. Possible valuesare: # targeted- Only targeted network daemons are protected. # strict -Full SELinux protection.SELINUXTYPE=targeted 安装SELinux [root@ebs-51660 ~]# yum install selinux-policy-targeted wget linuxmail.info/files/rhel6/postfixdovecotsasl.techeckmodule -M -m -o postfixdovecotsasl.mod postfixdovecotsasl.te
semodule_package -o postfixdovecotsasl.pp -m postfixdovecotsasl.mod
semodule -i postfixdovecotsasl.pp
-
安装 cyrus-sasl 软件包
[root@ebs-51660 ~]# yum install cyrus-sasl*(A)使用/etc/shadow文件验证
[root@ebs-51660 ~]# vi /etc/sysconfig/saslauthd
MECH=shadow
FLAGS=
[root@ebs-51660 ~]# vi /etc/sasl2/smtpd.conf
pwcheck_method: saslauthd
mech_list: plain login
(B)使用/etc/sasldb文件验证
[root@ebs-51660 ~]# vi /etc/sysconfig/saslauthd
#MECH=pam #注释掉原文此行
FLAGS=sasldb
[root@ebs-51660 ~]# vi /etc/sasl2/smtpd.conf
pwcheck_method: auxprop
auxprop_plugin: sasldb
mech_list: plain login
[root@ebs-51660 ~]# saslpasswd2 -c admin -u kingmed.com
按提示输入两次密码(不要与系统密码相同),首次操作会生成/etc/sasldb2文件。
[root@ebs-51660 ~]# chgrp postfix /etc/sasldb2
[root@ebs-51660 ~]# chmod 640 /etc/sasldb2
启动saslauthd
[root@ebs-51660 ~]#chkconfig saslauthd on
[root@ebs-51660 ~]#service saslauthd start
[root@ebs-51660 ~]# /usr/sbin/testsaslauthd -u admin -p '123456' #用系统密码测试
0: NO "authentication failed"
解决办法:
[root@ebs-51660 ~]# setsebool -P allow_saslauthd_read_shadow 1
如果还是不能成功,则看的main.cf文件配置是否有错
-
开放相关端口
[root@ebs-51660 ~]# vi /etc/sysconfig/iptables
-A INPUT -p tcp -m multiport --dports 25,80,110,143 -j ACCEPT
[root@ebs-51660 ~]# service iptables restart
-
重启postfix
[root@ebs-51660 ~]# chkconfig postfix on[root@ebs-51660 ~]# service postfix restart
-
检验配置是否正确
postfix 提供了check命令,可以检查当前postfix 的配置是否有问题、文件和目录权限是否正确 [root@ebs-51660 ~]# postfix check 没有错误就说明没有问题 -
发送邮件测试
echo 'test' | mail -s 'test' test@test.com -
Telnet登录验证
新安装的centos系统是没有安装telnet的,需要自己安装 检查是否安装[root@ebs-51660 ~]# rpm -qa telnet 安装[root@ebs-51660 ~]# yum install -y telnet 检查是否安装telent-server[root@ebs-51660 ~]# rpm -qa telnet-server 安装[root@ebs-51660 ~]# yum install telnet-server 这里是用虚拟用户即/etc/sasldb帐号,先取得用户名和密码的BASE64编码: [root@ebs-51660 sasl2]# printf "admin@fshongling.com" | openssl base64 bGl1eXVodWlAa2luZ21lZC5jb20= [root@ebs-51660 sasl2]# printf "123456" | openssl base64 bGl1eXVodWk= [root@ebs-51660 ~]# telnet localhost 25Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 mail.kingmed.com ESMTP Postfix
ehlo localhost
250-mail.kingmed.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH DIGEST-MD5 GSSAPI PLAIN CRAM-MD5 LOGIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
auth login
334 VXNlcm5hbWU6
bGl1eXVodWlAa2luZ21lZC5jb20= #liuyuhui@kingmed.com的BASE64编码
334 UGFzc3dvcmQ6
bGl1eXVodWk= #密码liuyuhui的BASE64编码
235 2.7.0 Authentication successful
mail from:liuyuhui@kingmed.com
250 2.1.0 Ok
rcpt to:jiangtao@kingmed.com
250 2.1.5 Ok
data
354 End data with . #回车后以点号(.)结束
hello,how are you?
250 2.0.0 Ok: queued as 934C83622
quit
221 2.0.0 Bye
Connection closed by foreign host.
来看下jiangtao用户家目录下是否有此邮件(注意queued as 934C83622):
[root@mail ~]# cat /home/jiangtao/Maildir/new/1375283408.Vfd00I3696M538506.mail.kingmed.com
Return-Path:
X-Original-To: jiangtao@kingmed.com
Delivered-To: jiangtao@kingmed.com
Received: from localhost (localhost [127.0.0.1])
(Authenticated sender: liuyuhui@kingmed.com)
by mail.kingmed.com (Postfix) with ESMTPA id 934C83622
for ; Wed, 31 Jul 2013 23:09:20 +0800 (CST)
Message-Id: <20130731150940.934C83622@mail.kingmed.com>
Date: Wed, 31 Jul 2013 23:09:20 +0800 (CST)
From: liuyuhui@kingmed.com
To: undisclosed-recipients:;
hello,how are you?
POP/ IMAP设置
为了让用户能在本地机器下载邮件,必须在服务器安装设置POP或IMAP。Dovecot是适用CentOS Linux邮件系统有名的imap/pop服务器之一,它支持maildir和mbox格式。
-
安装dovecot
[root@ebs-51660 ~]# yum -y install dovecot [root@ebs-51660 ~]# vim /etc/dovecot/dovecot.conf protocols = imap pop3 // 大概在20行的位置 listen = * // 27行左右 [root@ebs-51660 ~]# vim /etc/dovecot/conf.d/10-auth.conf disable_plaintext_auth = no // 9行,将yes改为no并去掉#号 auth_mechanisms = plain login // 97行 [root@ebs-51660 ~]# vim /etc/dovecot/conf.d/10-mail.conf mail_location = maildir:~/Maildir [root@ebs-51660 ~]# vim /etc/dovecot/conf.d/10-master.confservice auth {
unix_listener auth-userdb {
}
unix_listener /var/spool/postfix/private/auth {
mode = 0666
user = postfix
group = postfix
}
} [root@ebs-51660 ~]# vim /etc/dovecot/conf.d/10-ssl.conf ssl = no [root@ebs-51660 ~]# vim /etc/dovecot/conf.d/20-pop3.conf pop3_uidl_format = XuXv pop3_client_workarounds = outlook-no-nuls oe-ns-eoh配置完后使用dovecot -n查看所有配置。
启动dovecot:
[root@ebs-51660 ~]# chkconfig dovecot on
[root@ebs-51660 ~]# service dovecot start
现在你可以使用邮件客户端代理软件和系统用户及密码来连接我们的Dovecot服务器了。
未完待续 http://www.cnblogs.com/apexchu/p/4271264.html http://blog.chinaunix.net/uid-20362960-id-1699884.html http://my.oschina.net/u/2450048/blog/531171 http://www.mamicode.com/info-detail-1162987.html http://blog.jjonline.cn/linux/185.html