postfix+dovecot

本文涉及的产品
全局流量管理 GTM,标准版 1个月
公共DNS(含HTTPDNS解析),每月1000万次HTTP解析
云解析 DNS,旗舰版 1个月
简介:

 postfix

1  postfix提供 smtp协议用来投递邮件

默认端口25

mail root@westos.com

Subject: qwe

safsafg

adsf

.                                  ##用“.”结束录入并发送

EOT

mailq   ##查看邮件队列

postqueue -f     ##重新处理邮件队列

postsuper -d  **  ##删除错的邮件

默认情况下邮件端口只在127.0.0.1上开启

 

 

2配置

117

vim /etc/postfix/main.cf

76 myhostname = westos-mail.westos.com

83 mydomain = westos.com

99 myorigin = westos.com

116 inet_interfaces = all

164 mydestination = $myhostname, $mydomain, localhost

 

systemctl restart postfix.service

systemctl stop firewalld

217

vim /etc/postfix/main.cf

76 myhostname = qq-mail.qq.com

83 mydomain = qq.com

99 myorigin = qq.com

116 inet_interfaces = all

164 mydestination = $myhostname, $mydomain, localhost

 

systemctl restart postfix.service

systemctl stop firewalld

 

 

 

 

3邮件别名

vim /etc/aliases

别名:    真名       ##邮件别名

别名:   include:filename  ##邮件群发

vim filename

user1

user2

 

 

postalias /etc/aliases      ##使文件生效

 

测试

mail 别名

mail admin@qq.com

 

 

 

通过远程主机发邮件

17

yum install telnet -y

[root@dns-server Desktop]# telnet 172.25.254.117 25    ##25 端口

Trying 172.25.254.117...

Connected to 172.25.254.117.

Escape character is '^]'.

220 westos-mail.westos.com ESMTP Postfix

ehlo hello

250-westos-mail.westos.com

250-PIPELINING

250-SIZE 10240000

250-VRFY

250-ETRN

250-ENHANCEDSTATUSCODES

250-8BITMIME

250 DSN

mail from:root@westos.com      ###邮件发送端

250 2.1.0 Ok

rcpt to:root@qq.com           ###邮件接守端

250 2.1.5 Ok

data     ####数据

354 End data with <CR><LF>.<CR><LF>

adfasdgf

asdfagaa

gadgdfga

agfadfg

.

250 2.0.0 Ok: queued as C69BD2461FF

q

502 5.5.2 Error: command not recognized

^Cquit

quit                    ###退出

Connection closed by foreign host.

测试

217

[root@qq-mail ~]# mail

Heirloom Mail version 12.5 7/5/10.  Type ? for help.

"/var/spool/mail/root": 5 messages 1 new 4 unread

    1 root                  Sat May 20 03:38  23/736   "sadf"

 U  2 root                  Sat May 20 04:11  22/735   "qw"

 U  3 root                  Sat May 20 04:12  25/868   "wq"

 U  4 root                  Sat May 20 04:27  25/877   "safafaf"

>N  5 root@westos.com       Sat May 20 04:37  16/514   

& 5

Message  5:

From root@westos.com  Sat May 20 04:37:07 2017

Return-Path: <root@westos.com>

X-Original-To: root@qq.com

Delivered-To: root@qq.com

Status: R

 

adfasdgf

asdfagaa

gadgdfga

agfadfg

 

& q

Held 5 messages in /var/spool/mail/root

您在 /var/spool/mail/root 中有邮件

 

>  /var/spool/mail/root ##清空邮件

 

 

5 邮件客户端的访问控制

117

postconf -e "smtpd_client_restrictions = check_client_access hash:/etc/postfix/access"

   ###完成后会在/etc/postfix/main.cf文件最后出现680 smtpd_client_restrictions = check_client_access hash:/etc/postfix/access

 

vim /etc/postfix/access

 

477 172.25.254.17   REJECT

 

postmap /etc/postfix/access   ##加密access文件,会在/etc/postfix/生成access.db加密文件  真正读的文件是access.db而非access

 

systemctl restart postfix.service

 

测试

17

[root@dns-server Desktop]# telnet 172.25.254.117 25

Trying 172.25.254.117...

Connected to 172.25.254.117.

Escape character is '^]'.

220 westos-mail.westos.com ESMTP Postfix

mail from:root@westos.com

250 2.1.0 Ok

rcpt to:root@qq.com

554 5.7.1 <unknown[172.25.254.17]>: Client host rejected: Access denied   ##被拒绝

quit

221 2.0.0 Bye

Connection closed by foreign host.

 

 

 

 

 

 

 

 

##限制用户发送

117

systemctl status firewalld

firewalld.service - firewalld - dynamic firewall daemon

   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled)

   Active: inactive (dead)

 

systemctl start named

 

postconf -e "smtpd_sender_restrictions = check_sender_access hash:/etc/postfix/sender"

 

vim /etc/postfix/sender

student@westos.com  REJECT     ###REJECT后不能空格,否则格式会出错

 

postmap /etc/postfix/sender

 

systemctl restart postfix.service

 

测试

17

[root@dns-server 桌面]# telnet 172.25.254.117 25

Trying 172.25.254.117...

Connected to 172.25.254.117.

Escape character is '^]'.

220 westos-mail.westos.com ESMTP Postfix

mail from:student@westos.com                      

250 2.1.0 Ok

rcpt to:root@westos.com

554 5.7.1 <unknown[172.25.254.17]>: Client host rejected: Access denied

quit

221 2.0.0 Bye

Connection closed by foreign host.

 

 

##限制用户接收

117

postconf -e "smtpd_recipient_restrictions = check_recipient_access hash:/etc/postfix/recip"

 

vim /etc/postfix/recip

westos@westos.com

 

 

useradd westos

 

postmap /etc/postfix/recip

 

systemctl restart postfix.service

 

 

测试

17

[root@dns-server 桌面]# telnet 172.25.254.117 25

Trying 172.25.254.117...

Connected to 172.25.254.117.

Escape character is '^]'.

220 westos-mail.westos.com ESMTP Postfix

mail from:westos@westos.com

250 2.1.0 Ok

rcpt to:root@westos.com

250 2.1.5 Ok

data

354 End data with <CR><LF>.<CR><LF>

fasf

adsf

.

250 2.0.0 Ok: queued as 6E712EAC27

 

[root@dns-server 桌面]# telnet 172.25.254.117 25

Trying 172.25.254.117...

Connected to 172.25.254.117.

Escape character is '^]'.

220 westos-mail.westos.com ESMTP Postfix

mail from:root@westos.com

250 2.1.0 Ok

rcpt to:westos@westos.com

554 5.7.1 <unknown[172.25.254.17]>: Client host rejected: Access denied

 

 

 

##出站地址伪装

117

postconf -e "smtp_generic_maps = hash:/etc/postfix/generic"

 

vim /etc/postfix/generic

westos@westos.com          hello@sb.com

 

postmap /etc/postfix/generic

 

systemctl restart postfix.service

 

测试

su - westos

mail root@qq.com

[westos@westos-mail ~]$ mail root@qq.com

Subject: dstttttt

2

.

EOT

 

217

[root@qq-mail ~]# mail

Heirloom Mail version 12.5 7/5/10.  Type ? for help.

"/var/spool/mail/root": 8 messages 1 new 4 unread

    1 root                  Sat May 20 03:38  23/736   "sadf"

 U  2 root                  Sat May 20 04:11  22/735   "qw"

 U  3 root                  Sat May 20 04:12  25/868   "wq"

 U  4 root                  Sat May 20 04:27  25/877   "safafaf"

    5 root@westos.com       Sat May 20 04:37  17/525   

    6 westos@westos.com     Sat May 20 22:32  22/738   "wef"

    7 westos@westos.com     Sat May 20 22:35  22/743   "gfagagagtr"

>N  8 hello@sb.com          Sat May 20 22:46  21/713   "dstttttt"

&

 

 

 

##入站地址转换

117

先准备dns mx 记录解析

vim /etc/named.rfc1912.zones

37 zone "sb.com" IN {

 38         type master;

 39         file "westos.com.zone";

 40         allow-update { none; };

 41 };

cd /var/named/

cp -p qq.com.zone sb.com.zone

vim sb.com.zone

1 $TTL 1D

  2 @       IN SOA dns.sb.com. root.sb.com. (

  3                                         0       ; serial

  4                                         1D      ; refresh

  5                                         1H      ; retry

  6                                         1W      ; expire

  7                                         3H )    ; minimum

  8                         NS      dns.sb.com.

  9 dns                     A       172.25.254.117

 10 sb.com.                 MX 1    172.25.254.117.

 

systemctl restart named

 

postconf -e "virtual_alias_maps = hash:/etc/postfix/virtual"

 

vim /etc/postfix/virtual

虚拟名字                                真实用户

hello@sb.com         westos@westos.com

 

postmap /etc/postfix/virtual

 

systemctl restart postfix.service

 

测试

mail hello@sb.com

[root@westos-mail named]# mail hello@sb.com

Subject: 444

12

.

EOT

[root@westos-mail named]# su - westos

上一次登录:六 5月 20 22:55:33 EDT 2689pxs/0 上

[westos@westos-mail ~]$ mail

Heirloom Mail version 12.5 7/5/10.  Type ? for help.

"/var/spool/mail/westos": 1 message 1 new

>N  1 root                  Sat May 20 22:56  18/552   "444"

& quit

Held 1 message in /var/spool/mail/westos

You have mail in /var/spool/mail/westos

 

 

dovecot

1.

dovecot 用来提供收件协议

pop3        110

imap       143

imaps       993

pop3s       995

 

给定用户名称,密码,dovecot代我们去看这个用户的邮件

 

 

2.

217

yum install dovecot -y

17

yum imstall mutt -y

 

3

vim /etc/dovecot/dovecot.conf

24 protocols = imap pop3 lmtp

48 login_trusted_networks =0.0.0.0/0

49 disable_plaintext_auth = no

 

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

30 mail_location = mbox:~/mail:INBOX=/var/mail/%u

 

systemctl restart dovecot

 

useradd westos

passwd westos

 

su - westos

[westos@qq-mail ~]$ mkdir mail/.imap/ -p

[westos@qq-mail ~]$ touch mail/.imap/INBOX

 

 

 

测试

[westos@qq-mail ~]$ mail westos

Subject:

124

12

.

EOT

 

17

mutt -f pop://westos@172.25.254.217

 

###在root@qq中skel建立目录,文件 ,所有新用户都有skel中的内容,位置/home/新用户名

[root@qq-mail ~]# mkdir /etc/skel/mail/.imap -p

[root@qq-mail ~]# touch /etc/skel/mail/.imap/INBOX


 

 

 

 

 

 

 

 

本文转自 漂浮的天堂  51CTO博客,原文链接:http://blog.51cto.com/12774215/1929520,如需转载请自行联系原作者

目录
相关文章
|
7月前
|
存储 安全 Linux
linux centos7中使用 Postfix 和Dovecot搭建邮件系统
linux centos7中使用 Postfix 和Dovecot搭建邮件系统
369 1
|
7月前
|
存储 安全 Linux
linux中使用Postfix和Dovecot搭建邮箱系统服务
Postfix是一个开源的邮件传输代理(MTA),用于路由和传送电子邮件。它是一个可靠、安全且高性能的邮件服务器软件,常用于搭建邮件系统的核心组件之一。 Dovecot是一个开源的邮件服务软件,用于提供邮件访问服务,包括POP3和IMAP协议。它通常与Postfix配合使用,用于接收和存储邮件,以及为用户提供远程访问邮件的功能。
920 3
 linux中使用Postfix和Dovecot搭建邮箱系统服务
|
存储 运维 监控
centos7.6部署Postfix+Dovecot邮件系统
一、理论部分 电子邮件系统基于邮件协议来完成电子邮件的传输 常用的协议有:    简单邮件传输协议(SMTP):用于发送和中转发出的电子邮件,占用服务器的TCP/25端口    邮局协议版本3(POP3):用于将电子邮件存储到本地主机,占用服务器的TCP/110端口    internet消息访问协议版本4(IMAP4):用于在本地主机访问邮件,占用服务器的TCP/143端
470 0
centos7.6部署Postfix+Dovecot邮件系统
|
网络安全 数据安全/隐私保护
|
安全 网络协议 Linux
用 Postfix+Dovecot 在 CentOS7 上快速搭建自己的安全邮件服务器
用 Postfix+Dovecot 在 CentOS7 上快速搭建自己的安全邮件服务器,用 yum 安装实现快速,用 ssl 加密实现安全!
7579 0
|
网络协议 关系型数据库 测试技术