Centos7.1下用Postfix和Dovecot搭建邮件服务器

1、软件说明:

     Postfix是用来收发邮件的,它没有web页面,所以要配合本地的MUA(类似于foxmail,outlook之类的软件)来进行可视化的邮件管理操作。
     Dovecot 是一个开源的IMAP和POP3邮件服务器,支持Linux/Unix 系统。作为IMAP和POP3服务器,Dovecot并不负责从其他邮件服务器接收邮件,Dovecot只是将已经存储在邮件服务器上的邮件通过MUA显示出来。

2、安装软件:

安装之前,先卸载Centos默认的邮件传输代理:

yum remove sendmail

然后安装Postfix和Dovecot:

yum -y install postfix dovecot

安装完的版本分别为

postfix  2.10.1
dovecot  2.2.10

修改默认邮件传输代理:

alternatives --config mta

查看是否修改成功:

alternatives --display mta

第一行会显示mta - status is manual.则表示设置成功

3、设置域名解析:

需要添加两条记录,一般情况下10分钟左右会生效

记录类型主机记录解析线路(isp)记录值MX优先级TTL值
Amail默认服务器IP地址10 分钟
MX@默认mail.example.com1010 分钟

上面标红色的地方需要根据实际情况去修改。

4、修改软件配置:

①、修改Postfix配置:

vi /etc/postfix/main.cf
修改以下内容:

myhostname = mail.example.com
mydomain = example.com
myorigin = $mydomain
inet_interfaces = all
inet_protocols = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
local_recipient_maps =
mynetworks = 0.0.0.0/0
smtpd_banner = $myhostname ESMTP

并且在文件结尾加入以下内容:

#启用SMTP认证
smtpd_sasl_type = dovecot
smtpd_sasl_path = /var/spool/postfix/private/auth
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $myhostname
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination,reject_unknown_sender_domain
smtpd_client_restrictions = permit_sasl_authenticated
smtpd_sasl_security_options = noanonymous
proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps $virtual_mailbox_domains $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps $relocated_maps $transport_maps $mynetworks
②、修改Dovecot配置:
vi /etc/dovecot/dovecot.conf

修改的结果如下:

auth_mechanisms = plain login
base_dir = /var/run/dovecot/
debug_log_path = /var/log/dovecot_debug.log
disable_plaintext_auth = no
first_valid_uid = 1000
info_log_path = /var/log/dovecot_info.log
login_trusted_networks = 0.0.0.0/0
mail_location = mbox:~/mail:INBOX=/var/mail/%u
mbox_write_locks = fcntl
namespace inbox {
  inbox = yes
  location = mbox:~/mail:INBOX=/var/mail/%u
  mailbox Drafts {
    special_use = \Drafts
  }
  mailbox Junk {
    special_use = \Junk
  }
  mailbox Sent {
    special_use = \Sent
  }
  mailbox "Sent Messages" {
    special_use = \Sent
  }
  mailbox Trash {
    special_use = \Trash
  }
  prefix =
}
passdb {
  args = dovecot
  driver = pam
}
service auth {
  unix_listener /var/spool/postfix/private/auth {
    mode = 0666
    user = postfix
  }
  unix_listener auth-userdb {
    group = noreply
    mode = 0666
    user = noreply
  }
}
service imap-login {inet_listener imap {
    port = 143
  }
}
service pop3-login {
  inet_listener pop3 {
    port = 110
  }
}
ssl = no
ssl_cert = </etc/pki/dovecot/certs/dovecot.pem
ssl_key = </etc/pki/dovecot/private/dovecot.pem
userdb {
  driver = passwd
}

其实上面的配置文件并非一个,而是修改了/etc/dovecot/conf.d文件夹下的以下几个文件:

10-auth.conf
10-ssl.conf
10-mail.conf
10-master.conf
10-logging.conf

修改完成以后使用doveconf -n > dovecot-new.conf命令生成一个全新的综合的配置文件。

5、修改防火墙配置:

firewall-cmd --zone=public --permanent --add-service=imap
firewall-cmd --zone=public --permanent --add-service=smtp
firewall-cmd --zone=public --permanent --add-service=pop3
firewall-cmd --zone=public --add-port=25/tcp --permanent
firewall-cmd --zone=public --add-port=25/udp --permanent
firewall-cmd --zone=public --add-port=110/tcp --permanent
firewall-cmd --zone=public --add-port=110/udp --permanent
firewall-cmd --zone=public --add-port=143/tcp --permanent
firewall-cmd --zone=public --add-port=143/udp --permanent
firewall-cmd --reload

6、配置用户及权限:

useradd noreply
echo "pwdOfMail" | passwd --stdin noreply
sudo chmod 0775 /var/spool/mail/*

7、启动服务:

systemctl enable postfix
chkconfig postfix on
systemctl enable dovecot
chkconfig dovecot on
systemctl restart postfix/dovecot
systemctl status postfix/dovecot

8、在客户端登录:

以下以Outlook配置为例:

点子邮件地址:noreply@example.com
类型:IMAP/POP3(任选其一)
用户名:noreply
密码:pwdOfMail
接收服务器:mail.example.com 
接收端口:143
接收是否使用SSL连接:不使用
发送服务器:
发送端口:25
发送是否使用SSL连接:不使用

添加完成之后就可以用Outlook发送邮件了,这样也可以在代码程序中使用系统邮箱了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值