postfix折腾记

1.DNS设置

Type     Host     Destination                 Priority    TTL

MX       @        mail.yourdomain.com 10            3600

A          mail     192.168.0.1                                3600

添加域名解析记录,如上。

2.安装postfix

先更新 yum -y update

再 安装 yum -y install postfix

3.安装证书和私钥

mkdir /etc/postfix/ssl

cd /etc/postfix/ssl

openssl req -x509 -nodes -newkey rsa:2048 -keyout server.key -out server.crt -nodes -days 3650

4.配置postfix

vim /etc/postfix/main.cf

修改下列配置项

myhostname = mail.yourdomain.com  主机名

mydomain = yourdomain.com 域名

myorigin = $mydomain 此项用于在发件人的名称

home_mailbox = mail/ 邮箱目录

mynetworks 此项是postfix接收的客户,不必配置,默认是 mynetworks_style =  subnet

inet_interfaces = all 此项是postfix监听的ip地址,监听所有IP地址

inet_protocols = all 支持IP4和IP6

mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain 本机地址

smtpd_sasl_type = dovecot  类型

smtpd_sasl_path = private/auth 路径  

smtpd_sasl_local_domain =

smtpd_sasl_security_options = noanonymous 禁止匿名

broken_sasl_auth_clients = yes

smtpd_sasl_auth_enable = yes

smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination 接收者限制

smtp_tls_security_level = may

smtpd_tls_security_level = may

smtp_tls_note_starttls_offer = yes

smtpd_tls_loglevel = 1

smtpd_tls_key_file = /etc/postfix/ssl/server.key

smtpd_tls_cert_file = /etc/postfix/ssl/server.crt

smtpd_tls_received_header = yes

smtpd_tls_session_cache_timeout = 3600s

tls_random_source = dev:/dev/urandom

配置另一个文件 vim /etc/postfix/master.cf

/etc/postfix/master.cf

找到下面的文字

# service type private unpriv chroot wakeup maxproc command + args

# (yes) (yes) (yes) (never) (100) # ==========================================================================

smtp inet n - n - - smtpd

在下面添加:

submission inet n - n - - smtpd

-o syslog_name=postfix/submission

-o smtpd_sasl_auth_enable=yes

-o smtpd_recipient_restrictions=permit_sasl_authenticated,reject

-o milter_macro_daemon_name=ORIGINATING

smtps inet n - n - - smtpd

-o syslog_name=postfix/smtps

-o smtpd_sasl_auth_enable=yes

-o smtpd_recipient_restrictions=permit_sasl_authenticated,reject

-o milter_macro_daemon_name=ORIGINATING

5 安装 Dovecot

yum -y install dovecot

修改配置

vim /etc/dovecot/conf.d/10-master.conf

找到下面文字

# Postfix smtp-auth

在它下面添加:

# Postfix smtp-auth

unix_listener /var/spool/postfix/private/auth {‘

mode = 0660

user = postfix

group = postfix }

修改另一个i配置

vim /etc/dovecot/conf.d/10-auth.conf

auth_mechanisms = plain login

login 是添上去的

修改配置 vim /etc/dovecot/conf.d/10-mail.conf 

找到下面文字

# # #mail_location =

改成:

mail_location = maildir:~/mail

修改配置  vim /etc/dovecot/conf.d/20-pop3.conf

找到下面文字

#pop3_uidl_format = %08Xu%08Xv

去掉注释:

pop3_uidl_format = %08Xu%08Xv

重启程序:

systemctl restart postfix

systemctl enable postfix 增加自启动

systemctl restart dovecot

  • # netstat -lntp | grep dovecot         
  • tcp        0      0 0.0.0.0:993                 0.0.0.0:*                   LISTEN      2547/dovecot         
  • tcp        0      0 0.0.0.0:995                 0.0.0.0:*                   LISTEN      2547/dovecot         
  • tcp        0      0 :::993                      :::*                        LISTEN      2547/dovecot         
  • tcp        0      0 :::995                      :::*                        LISTEN      2547/dovecot 

systemctl enable dovecot 增加自启动

如果有防火墙:

firewall-cmd --permanent --add-service=smtp

firewall-cmd --permanent --add-port=587/tcp

firewall-cmd --permanent --add-port=465/

tcp firewall-cmd --permanent --add-port=110/tcp

firewall-cmd --permanent --add-service=pop3s

firewall-cmd --permanent --add-port=143/tcp

firewall-cmd --permanent --add-service=imaps

firewall-cmd --permanent --add-service=http

firewall-cmd --reload

6.安装 mailx

yum install -y mailx

配置

vim /etc/mail.rc

# 启动

ssl set ssl-verify=ignore

# 邮箱账户

set from=xxxxxx@126.com

# smtp邮箱类型

set smtp="smtps://smtp.126.com:465"

# 邮箱账户

set smtp-auth-user="xxxxxxx@126.com"

# 邮箱授权密码 set smtp-auth-password=xxxxxxx

# login模式

set smtp-auth=login

# 指定文件目录

set nss-config-dir=/etc/postfix/ssl

7.测试

发送测试

echo  test | mail -s "test"  xxx@sina.com

登录新浪邮箱,发现已经收到了。

接收测试

[root@mail ~]# telnet mail.domain.com 110
Trying 47.106.14.53...
Connected to mail.domain.com.
Escape character is '^]'.
+OK Dovecot ready.
user test   #用户名
+OK
pass pps123456 #密码
+OK Logged in.
list           #查看邮件表列  
+OK 3 messages:
1 318
2 316
3 320
.
retr 3  #查看第三封邮件
+OK 320 octets
Return-Path: <admin@domain.com>
X-Original-To: test@domain.com
Delivered-To: test@domain.com
Received: from mail.domain.com (mail.domain.com [47.106.14.53])
        by mail.domain.com (Postfix) with SMTP id 72B6D2E4A3E
        for <test@domain.com>; Sat,  2 Mar 2019 22:53:29 +0800 (CST)
subject:title data 22.52

current data 22.52
.
quit
+OK Logging out.
Connection closed by foreign host.

参考文章:https://hostpresto.com/community/tutorials/how-to-setup-an-email-server-on-centos7/

https://blog.csdn.net/xianglingchuan/article/details/88096573

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值