postfix+dovecot

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了postfix+dovecot相关的知识,希望对你有一定的参考价值。

postfix

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

默认端口25

mail [email protected]

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 [email protected]

 

 

 

通过远程主机发邮件

17

yum install telnet -y

[[email protected] 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:[email protected]      ###邮件发送端

250 2.1.0 Ok

rcpt to:[email protected]           ###邮件接守端

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

[[email protected] ~]# 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 [email protected]       Sat May 20 04:37  16/514   

& 5

Message  5:

From [email protected]  Sat May 20 04:37:07 2017

Return-Path: <[email protected]>

X-Original-To: [email protected]

Delivered-To: [email protected]

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

[[email protected] 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:[email protected]

250 2.1.0 Ok

rcpt to:[email protected]

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

[email protected]  REJECT     ###REJECT后不能空格,否则格式会出错

 

postmap /etc/postfix/sender

 

systemctl restart postfix.service

 

测试

17

[[email protected] 桌面]# 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:[email protected]                      

250 2.1.0 Ok

rcpt to:[email protected]

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

[email protected]

 

 

useradd westos

 

postmap /etc/postfix/recip

 

systemctl restart postfix.service

 

 

测试

17

[[email protected] 桌面]# 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:[email protected]

250 2.1.0 Ok

rcpt to:[email protected]

250 2.1.5 Ok

data

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

fasf

adsf

.

250 2.0.0 Ok: queued as 6E712EAC27

 

[[email protected] 桌面]# 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:[email protected]

250 2.1.0 Ok

rcpt to:[email protected]

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

[email protected]          [email protected]

 

postmap /etc/postfix/generic

 

systemctl restart postfix.service

 

测试

su - westos

mail [email protected]

[[email protected] ~]$ mail [email protected]

Subject: dstttttt

2

.

EOT

 

217

[[email protected] ~]# 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 [email protected]       Sat May 20 04:37  17/525   

    6 [email protected]     Sat May 20 22:32  22/738   "wef"

    7 [email protected]     Sat May 20 22:35  22/743   "gfagagagtr"

>N  8 [email protected]          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

虚拟名字                                真实用户

[email protected]         [email protected]

 

postmap /etc/postfix/virtual

 

systemctl restart postfix.service

 

测试

mail [email protected]

[[email protected] named]# mail [email protected]

Subject: 444

12

.

EOT

[[email protected] named]# su - westos

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

[[email protected] ~]$ 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

[[email protected] ~]$ mkdir mail/.imap/ -p

[[email protected] ~]$ touch mail/.imap/INBOX

 

 

 

测试

[[email protected] ~]$ mail westos

Subject:

124

12

.

EOT

 

17

mutt -f pop://[email protected]

 

###在[email protected]中skel建立目录,文件 ,所有新用户都有skel中的内容,位置/home/新用户名

[[email protected] ~]# mkdir /etc/skel/mail/.imap -p

[[email protected] ~]# touch /etc/skel/mail/.imap/INBOX


以上是关于postfix+dovecot的主要内容,如果未能解决你的问题,请参考以下文章

如何在Linux停止和启动postfix服务的命令

postfix启动失败

postfix邮件服务

Postfix 不发送邮件

Postfix邮件

CentOS 7之Postfix部署系列postfix和Dovecot配置