Linux--RH254---unit4 postfix电子邮件

unit 4 postfix

准备:

重置虚拟机,配置虚拟机网络及yum源
发送端

yum install bind -y             ##安装bind


systemctl start named           ##启动bind
systemctl stop firewalld        ##关闭防火墙
systemctl disable firewalld     ##开机不自启
vim /etc/named.conf             ##编辑named主配置文件
 10 options {
 11 //      listen-on port 53 { 127.0.0.1; };
 12 //      listen-on-v6 port 53 { ::1; };
 13         directory       "/var/named";
 14         dump-file       "/var/named/data/cache_dump.db";
 15         statistics-file "/var/named/data/named_stats.txt";
 16         memstatistics-file "/var/named/data/named_mem_stats.txt";
 17 //      allow-query     { localhost; };
 31         dnssec-enable yes;
 32         dnssec-validation no;

 33         dnssec-lookaside auto;


vim /etc/named.rfc1912.zones    ##编辑配置文件
 25 zone "westos.com" IN {
 26         type master;
 27         file "westos.com.zone";
 28         allow-update { none; };
 29 };
 30
 31 zone "qq.com" IN {
 32         type master;
 33         file "qq.com.zone";
 34         allow-update { none; };

 35 };


cd /var/named/
cp -p named.localhost westos.com.zone
vim westos.com.zone             ##编辑westos.com.zone
$TTL 1D
@       IN SOA  dns.westos.com. root.westos.com. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
                NS      dns.westos.com.
dns             A       172.25.254.131

westos.com.     MX 1    172.25.254.131.


cp -p westos.com.zone qq.com.zone
vim qq.com.zone                 ##编辑qq.com.zone
$TTL 1D
@       IN SOA  dns.qq.com. root.qq.com. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
                NS      dns.qq.com.
dns             A       172.25.254.131

qq.com.         MX 1    172.25.254.231.


systemctl restart named       ##重启named


测试(发送端和接受端)
vim /etc/resolv.conf          ##dns解析
nameserver 172.25.254.131
dig -t mx westos.com

dig -t mx qq.com



1.基本信息
postfix提供smtp协议用来投递邮件
默认端口25
/var/log/maillog         ##服务日志
默认情况下邮件端口只在127.0.0.*上开启

2.配置
发送端:
vim /etc/postfix/main.cf                     ##编辑配置文件
 76 myhostname = westos-mail.westos.com      ##指定mta主机名称
 83 mydomain = westos.com                    ##指定mta的域名
 99 myorigin = $mydomain                     ##指定邮件来源结尾(@后面的字符内容)
116 inet_interfaces = all                    ##25端口开启的网络接口
164 mydestination = $myhostname, $mydomain, localhost    ##接收邮件结尾字符的指定
systemctl restart postfix.service            ##重启服务
systemctl stop firewalld                     ##关闭防火墙

systemctl disable firewalld                  ##开机不自启



接受端:
vim /etc/postfix/main.cf                     ##编辑配置文件
 76 myhostname = qq-mail.qq.com              ##指定mta主机名称
 83 mydomain = qq.com                        ##指定mta的域名
 99 myorigin = $mydomain                     ##指定邮件来源结尾(@后面的字符内容)
116 inet_interfaces = all                    ##25端口开启的网络接口
164 mydestination = $myhostname, $mydomain, localhost   ##接收邮件结尾字符的指定
systemctl restart postfix.service            ##重启服务
systemctl stop firewalld                     ##关闭防火墙

systemctl disable firewalld                  ##开机不自启



3.测试
发送端:
mail root@qq.com     ##向qq.com发送邮件
Subject: hello       ##标题
linux                ##内容
.                    ##用'.'来结束录入内容并发送此邮件
EOT
mailq                ##查看邮件队列
Mail queue is empty  ##邮件队列为空,表示邮件已发送
postqueue -f         ##重新处理邮件队列

postsuper -d id      ##删除邮件


接受端:

mail                 ##查看邮件



4.邮件别名
接收端:
vim /etc/aliases
别名:        真名                ##邮件别名
admin:          root
别名:        :include:filename   ##邮件群发

moreuser:       :include:/etc/postfix/moreuser


vim /etc/postfix/moreuser           ##群发名单
user1

user2


postalias /etc/aliases              ##刷新/etc/aliases

systemctl restart postfix.service   ##重启服务


测试
发送端
mail 别名@域名

mail admin@qq.com        ##向admin发邮件


mail moreuser@qq.com     ##群发邮件


接收端

mail                ##查看邮件,admin的邮件由root接收


mail -u student     ##查看student的邮件



5.通过远程主机测试邮件服务
在真机中

yum install telnet -y      ##安装telnet


telnet 172.25.254.131 25
mail from:root@westos.com  ##发送端
rcpt to:root@qq.com        ##接收端
data
输入邮件内容

quit                       ##退出


测试
接收端

mail                ##查看邮件



6.邮件客户端的访问控制
##限制客户端##

发送端
postconf -e "smtpd_client_restrictions = check_client_access hash:/etc/postfix/access"
vim /etc/postfix/main.cf                     ##配置文件
smtpd_client_restrictions = check_client_access hash:/etc/postfix/access    ##文件最后自动生成这句话
vim /etc/postfix/access
172.25.254.60 REJECT                ##限制60主机的远程控制
postmap /etc/postfix/access         ##加密,生成.db文件
/etc/postfix/access.db

systemctl restart postfix.service   ##重启服务


测试
[root@foundation60 ~]# telnet 172.25.254.131 25      ##60主机远程控制邮件服务被拒
Trying 172.25.254.131...
Connected to 172.25.254.131.
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.31]>: Client host rejected: Access denied



##限制用户发送##
postconf -e "smtpd_sender_restrictions = check_sender_access hash:/etc/postfix/sender"
vim /etc/postfix/main.cf                     ##配置文件
smtpd_sender_restrictions = check_sender_access hash:/etc/postfix/sender    ##文件最后自动生成这句话
vim /etc/postfix/sender
student@westos.com      REJECT      ##限制student用户发送邮件
postmap /etc/postfix/sender         ##加密,生成.db文件
/etc/postfix/sender.db

systemctl restart postfix.service   ##重启服务


测试
[kiosk@foundation60 Desktop]$ telnet 172.25.254.131 25   ##student用户发送邮件被拒
Trying 172.25.254.131...
Connected to 172.25.254.131.
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 <student@westos.com>: Sender address rejected: Access denied



##限制用户接收##
postconf -e "smtpd_recipient_restrictions = check_recipient_access hash:/etc/postfix/recip"
vim /etc/postfix/main.cf                     ##配置文件
smtpd_recipient_restrictions = check_recipient_access hash:/etc/postfix/recip     ##文件最后自动生成这句话
vim /etc/postfix/recip
westos@westos.com       REJECT     ##限制westos用户接收邮件
postmap /etc/postfix/recip         ##加密,生成.db文件
/etc/postfix/recip.db

systemctl restart postfix.service   ##重启服务


测试
[kiosk@foundation60 Desktop]$ telnet 172.25.254.131 25  ##westos用户接收邮件被拒   
Trying 172.25.254.131...
Connected to 172.25.254.131.
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 <westos@westos.com>: Recipient address rejected: Access denied



##出站地址伪装##
postconf -e "smtp_generic_maps = hash:/etc/postfix/generic"
vim /etc/postfix/main.cf                     ##配置文件
smtp_generic_maps = hash:/etc/postfix/generic
vim /etc/postfix/generic
westos@westos.com       hello@yy.com   ##出站地址由westos@westos.com伪装成hello@yy.com
postmap /etc/postfix/generic         ##加密,生成.db文件
/etc/postfix/generic.db

systemctl restart postfix.service   ##重启服务


测试
发送端
su - westos

mail root@qq.com                   ##westos用户发送邮件,出站地址为westos@westos.com


接收端
[root@qq-mail ~]# mail             ##接收端接收的邮件出站地址为hello@yy.com
Heirloom Mail version 12.5 7/5/10.  Type ? for help.
"/var/spool/mail/root": 1 message 1 new
>N  1 hello@yy.com          Tue May 23 02:36  21/713   "westos"
& 1
Message  1:
From hello@yy.com  Tue May 23 02:36:21 2017
Return-Path: <hello@yy.com>
X-Original-To: root@qq.com
Delivered-To: root@qq.com
Date: Tue, 23 May 2017 02:36:20 -0400
To: root@qq.com
Subject: westos
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
From: hello@yy.com
Status: R

hello

& q
Held 1 message in /var/spool/mail/root

You have mail in /var/spool/mail/root



##入站地址转换##
dns mx 记录解析先做好
vim /etc/named.rfc1912.zones    ##编辑配置文件
zone "yy.com" IN {
        type master;
        file "yy.com.zone";
        allow-update { none; };
};
cd /var/named/
cp -p westos.com.zone yy.com.zone
vim yy.com.zone             ##编辑yy.com.zone
$TTL 1D
@       IN SOA  dns.yy.com. root.yy.com. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
                NS      dns.yy.com.
dns             A       172.25.254.131
yy.com.         MX 1    172.25.254.131.

systemctl restart named       ##重启named



postconf -e "virtual_alias_maps = hash:/etc/postfix/virtual"
vim /etc/postfix/main.cf                     ##配置文件
virtual_alias_maps = hash:/etc/postfix/virtual
vim /etc/postfix/virtual
虚拟名字         真实名字
hello@yy.com    westos@westos.com    ##入站地址由hello@yy.com转换成westos@westos.com
postmap /etc/postfix/virtual         ##加密,生成.db文件
/etc/postfix/virtual.db

systemctl restart postfix.service   ##重启服务


测试
发送端

mail hello@yy.com                   ##向hello@yy.com地址发送邮件


接收端
[root@westos-mail ~]# su - westos
[westos@westos-mail ~]$ mail        ##westos用户接收
Heirloom Mail version 12.5 7/5/10.  Type ? for help.
"/var/spool/mail/westos": 1 message 1 new
>N  1 root                  Tue May 23 02:55  18/556   "hello"
& 1
Message  1:
From root@westos.com  Tue May 23 02:55:36 2017
Return-Path: <root@westos.com>
X-Original-To: hello@yy.com
Delivered-To: westos@westos.com
Date: Tue, 23 May 2017 02:55:36 -0400
To: hello@yy.com
Subject: hello
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
From: root@westos.com (root)
Status: R

haha

& q

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





7.dovecot
1)dovecot基本信息
dovecot用来提供收件协议
pop3    110
imap    143
imaps    993
pop3s    995
给定用户名称,用户密码,dovecot程序代我们去看这个用户的邮件文件
2)安装
yum install dovecot -y                 ##安装dovecot

systemctl start dovecot                ##开启dovecot


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.service      ##重启dovecot
passwd westos                          ##设定westos用户密码
mkdir /home/westos/mail/.imap -p          ##创建mail/.imap

touch /home/westos/mail/.imap/INBOX       ##创建INBOX文件



测试

yum install mutt -y


mutt -f pop://westos@172.25.254.131





8.postfix+thunderbird
发送端
su - student
mkdir mail/.imap -p

touch mail/.imap/INBOX


真机

yum install /software/thunderbird-31.2.0-1.el7.x86_64.rpm -y   ##安装thunderbird


在应用程序中打开thunderbird

单击skip this and use my existing email


填完your name和email address,单击continue


填写完所有信息单击re-test后再单击done


I understand the risks前打钩,单击done


单击Indox,单击Get Messages,输入密码即可



9.postfix+mariadb
*)准备工作
mv /etc/postfix/main.cf /mnt/

yum reinstall postfix.x86_64 -y              ##重新安装postfix


vim /etc/postfix/main.cf                     ##编辑配置文件
 76 myhostname = westos-mail.westos.com      ##指定mta主机名称
 83 mydomain = westos.com                    ##指定mta的域名
 99 myorigin = $mydomain                     ##指定邮件来源结尾(@后面的字符内容)
116 inet_interfaces = all                    ##25端口开启的网络接口

164 mydestination = $myhostname, $mydomain, localhost    ##接收邮件结尾字符的指定


systemctl restart postfix.service            ##重启服务


yum install httpd php php-mysql mariadb-server -y     ##安装httpd php php-mysql mariadb-server


systemctl start mariadb                  ##开启mariadb
vim /etc/my.cnf                          ##编辑配置文件

skip-networking=1                        ##阻断监听


systemctl restart mariadb                ##重启服务


mysql_secure_installation                ###第一次安装mysql后通过此命令对mysql进行设置


cd /var/www/html
tar jxf /mnt/phpMyAdmin-3.4.0-all-languages.tar.bz2
rm -fr *.bz2
mv phpMyAdmin-3.4.0-all-languages/ myadmin
cd myadmin/
cp config.sample.inc.php config.inc.php
vim config.inc.php

$cfg['blowfish_secret'] = 'mysql'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */


systemctl restart httpd


测试

访问172.25.254.131/myadmin创建数据库和表



mysql -uroot -p123
create user postuser@localhost identified by 'postuser';

grant select,update,insert on email.* to postuser@localhost;



*)配置
vim /etc/postfix/mailuser.cf     ##用户名称查询
hosts = localhost                ##数据库所在主机
user = postuser                  ##登陆数据库的用户
password = postuser              ##登陆数据库的密码
dbname = email                   ##postfix要查询的名称
table = emailuser                ##postfix要查询的表的名称
select_field = username          ##postfix要查询的字段

where_field = username           ##用户给定postfix的查询条件


测试
postmap -q "wang@wang.com" mysql:/etc/postfix/mailuser.cf

wang@wang.com



vim /etc/postfix/maildomain.cf   ##用户域名查询
hosts = localhost                ##数据库所在主机
user = postuser                  ##登陆数据库的用户
password = postuser              ##登陆数据库的密码
dbname = email                   ##postfix要查询的名称
table = emailuser                ##postfix要查询的表的名称
select_field = domain            ##postfix要查询的字段

where_field = domain             ##用户给定postfix的查询条件


测试
postmap -q "wang.com" mysql:/etc/postfix/maildomain.cf

wang.com



vim /etc/postfix/mailbox.cf      ##用户邮箱位置查询
hosts = localhost                ##数据库所在主机
user = postuser                  ##登陆数据库的用户
password = postuser              ##登陆数据库的密码
dbname = email                   ##postfix要查询的名称
table = emailuser                ##postfix要查询的表的名称
select_field = maildir           ##postfix要查询的字段

where_field = username           ##用户给定postfix的查询条件


测试
postmap -q "wang@wang.com" mysql:/etc/postfix/mailbox.cf

/mnt/wang.com/wang/



访问172.25.254.131/myadmin创建数据表


groupadd -g 666 vmail
useradd -s /sbin/nologin -u 666 vmail -g 666
postconf -e "virtual_mailbox_base = /home/vmail"
postconf -e "virtual_uid_maps = static:666"
postconf -e "virtual_gid_maps = static:666"
postconf -e "virtual_alias_maps = mysql:/etc/postfix/mailuser.cf"
postconf -e "virtual_mailbox_domains = mysql:/etc/postfix/maildomain.cf"
postconf -e "virtual_mailbox_maps = mysql:/etc/postfix/mailbox.cf"

systemctl restart postfix.service


mail wang@wang.com
cd /home/vmail/wang.com/wang

cat new/1495539641.Vfd01I1a9efdcM42741.westos-mail.westos.com


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值