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


 

 

 

 

 

 

 

 

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

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
阿里云服务器怎么设置密码?怎么停机?怎么重启服务器?
如果在创建实例时没有设置密码,或者密码丢失,您可以在控制台上重新设置实例的登录密码。本文仅描述如何在 ECS 管理控制台上修改实例登录密码。
9943 0
使用NAT网关轻松为单台云服务器设置多个公网IP
在应用中,有时会遇到用户询问如何使单台云服务器具备多个公网IP的问题。 具体如何操作呢,有了NAT网关这个也不是难题。
26756 0
阿里云服务器ECS远程登录用户名密码查询方法
阿里云服务器ECS远程连接登录输入用户名和密码,阿里云没有默认密码,如果购买时没设置需要先重置实例密码,Windows用户名是administrator,Linux账号是root,阿小云来详细说下阿里云服务器远程登录连接用户名和密码查询方法
11562 0
windows server 2008阿里云ECS服务器安全设置
最近我们Sinesafe安全公司在为客户使用阿里云ecs服务器做安全的过程中,发现服务器基础安全性都没有做。为了为站长们提供更加有效的安全基础解决方案,我们Sinesafe将对阿里云服务器win2008 系统进行基础安全部署实战过程! 比较重要的几部分 1.
9129 0
阿里云服务器如何登录?阿里云服务器的三种登录方法
购买阿里云ECS云服务器后如何登录?场景不同,阿里云优惠总结大概有三种登录方式: 登录到ECS云服务器控制台 在ECS云服务器控制台用户可以更改密码、更换系.
13690 0
阿里云ECS云服务器初始化设置教程方法
阿里云ECS云服务器初始化是指将云服务器系统恢复到最初状态的过程,阿里云的服务器初始化是通过更换系统盘来实现的,是免费的,阿里云百科网分享服务器初始化教程: 服务器初始化教程方法 本文的服务器初始化是指将ECS云服务器系统恢复到最初状态,服务器中的数据也会被清空,所以初始化之前一定要先备份好。
7310 0
阿里云服务器ECS登录用户名是什么?系统不同默认账号也不同
阿里云服务器Windows系统默认用户名administrator,Linux镜像服务器用户名root
4435 0
+关注
20382
文章
0
问答
文章排行榜
最热
最新
相关电子书
更多
《2021云上架构与运维峰会演讲合集》
立即下载
《零基础CSS入门教程》
立即下载
《零基础HTML入门教程》
立即下载