首页 > 代码库 > postfix+dovecot

postfix+dovecot

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


postfix+dovecot