主页 > 建站 > centos搭建Postfix+dovecot邮件服务器

centos搭建Postfix+dovecot邮件服务器

2015年4月15日 centos搭建Postfix+dovecot邮件服务器无评论 阅读: 11,442 次

搭建Postfix邮件服务器详解:

一、环境准备
1、首先关闭sendmail服务

service sendmail stop

2、chkconfig sendmail off(关闭开机自启动)

3、改主机名/etc/sysconfig/network
HOSTNAME="iytc.net"

二、安装postfix 软件包

1、软件安装
yum install -y postfix

2、修改postfix配置文件

vim /etc/postfix/main.cf
myhostname = mail.iytc.net
mydomain = iytc.net
myorigin = $mydomain

注意屏蔽inet_interfaces = localhost
inet_interfaces = all
mydestination = $myhostname, $mydomain, localhost

3、重启postfix 服务,加入自启动

service postfix restart
chkconfig postfix on

现在可以发信了
mail ywb94@sohu.com

三、安装IMAP收信软件dovecot
yum -y install dovecot

vi /etc/dovecot/dovecot.conf

#找到login_trusted_network,改为
login_trusted_network = 0.0.0.0/0

vi /etc/dovecot/conf.d/10-mail.conf

#找到mail_location设置邮箱的路径
mail_location = mbox:~/mail:INBOX=/var/mail/%u

开启服务
service dovecot restart
chkconfig dovecot on
可以收邮件了

 

四、加发送认证,配置saslauthd,这个软件默认是安装的

修改saslauthd 配置文件

vi /etc/sysconfig/saslauthd

设置MECH=shadow

service saslauthd restart

chkconfig saslauthd on

创建邮箱用户

useradd zhubf

passwd zhubf

echo zhubf |passwd --stdin zhubf

进行密码验证测试

testsaslauthd -u zhubf -p 'zhubf'

0: OK "Success."

若没有通过,可能是防火墙或selinux的设置问题。

在postfix的主配置文件/etc/postfix/main.cf添加如下权限设置

smtpd_sasl_auth_enable = yes

smtpd_sasl_local_domain = ''

smtpd_recipient_restrictions =permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination

broken_sasl_auth_clients = yes

smtpd_client_restrictions = permit_sasl_authenticated

smtpd_sasl_security_options = noanonymous

重启postfix 服务

如果SMTP发信失败,查看日志中提示“no applicable SASL mechanisms”时安装如下插件

yum install cyrus-sasl-plain

Ubuntu下:

apt-get install libsasl2-modules

补充:

1、添加POP3支持
vi /etc/dovecot/dovecot.conf

protocols = imap pop3 (修改)
新建INBOX目录
[root@mail ~]# mkdir -pv /home/zhang3/mail/.imap/INBOX
[root@mail ~]# chown -R zhang3 /home/zhang3/mail/.imap/INBOX

2、添加收信SSL认证
跳到/etc/dovecot/conf.d/中一通改
改10-auth.conf,禁止明文传输
disable_plaintext_auth = yes
#兼容用户名和邮箱地址格式登录
auth_username_format =%n
改10-ssl.conf
ssl = required
ssl_cert = </etc/pki/dovecot/certs/dovecot.pem
ssl_key = </etc/pki/dovecot/private/dovecot.pem
改10-master.conf
inet_listener pop3s {
port = 995
ssl = yes
}

3、添加发信SSL认证

一:创建smtpd.pem文件

cd /etc/pki/tls/certs

make smtpd.pem

cp smtpd.pem /etc/postfix

  1. 编辑主配置文件:

vi /etc/postfix/main.cf

在行尾加入如下内容:

smtp_use_tls = yes

smtpd_use_tls = yes

smtp_tls_note_starttls_offer = yes

smtpd_tls_key_file = /etc/postfix/smtpd.pem

smtpd_tls_cert_file = /etc/postfix/smtpd.pem

smtpd_tls_CAfile = /etc/postfix/smtpd.pem

smtpd_tls_loglevel = 1

smtpd_tls_received_header = yes

smtpd_tls_session_cache_timeout = 3600s

  1. 编辑master.cf这个文件

vi /etc/postfix/master.cf

smtps     inet  n       -       n       -       -       smtpd

-o smtpd_tls_wrappermode=yes

-o smtpd_sasl_auth_enable=yes

  1. 编辑dovecot配置文件/etc/dovecot/dovecot.conf:

protocols = imap  pop3

ssl = required
ssl_cert = </etc/postfix/smtpd.pem
ssl_key = </etc/postfix/smtpd.pem

  1. 启动相关服务:

/etc/init.d/postfix restart

/etc/init.d/dovecot restart

/etc/init.d/saslauthd restar

 

发表评论

新用户的评论需审核后才会显示;

电子邮件地址不会被公开;
必填项已用*标注