linux服务之postfix

postfix
##############################

准备工作需要配置DNS服务器

dns                  A         172.25.254.121
westos.com.    MX 1    172.25.254.121.
qq.com.           MX 1    172.25.254.221.

###############################

1.基础知识和定义

定义:

MUA(Mail User Agent):MUA就是“邮件用户代理”。邮件需要代理,这是由于通常Client端的计算机无法直接寄信所以,需要通过MUA帮我们传递信件,不论是送信还是收信,Client端用户都需要通过各个操作系统提供的MUA才能够使用邮件系统。


MUA主要的功能就是接收邮件主机的电子邮件,并提供用户浏览与编写邮件的功能。


MTA(Mail Transfer Agent):MUA是用在Client端的软件,而MTA是用在邮件主机上的软件,它也是主要的邮件服务器。MTA就是“邮件传送代理”的意思,既然是“传送代理”,那么用户寄信与收信时,都找MTA就对了!因为它负责帮用户传送。

MUA主要的功能就是将电子邮件从一台主机发送到另一台主机。MTA使用SMTP(简单邮件传输协议)来传送电子邮件。为了让你更清楚,我们平时用来收发邮件的客户端也使用SMTP,但它们并不是MTA。它们只是一个应用程序,提供某种接口让用户收发邮件。它们被称为MUA(Mial User Agent)—邮件用户代理。不过要注意,MTA会将信件送给目的地的MTA而不是目的地的MUA。


MDA(Mail Delivery Agent):“邮件投递代理”主要的功能就是将MTA接收的信件依照信件的流向(送到哪里)将该信件放置到本机账户下的邮件文件中(收件箱),或者再经由MTA将信件送到下个MTA。如果信件的流向是到本机,这个邮件代理的功能就不只是将由MTA传来的邮件放置到每个用户的收件箱,它还可以具有邮件过滤与其他相关功能。


Postfix: 是一个标准的MTA「Mail Transfer Agent」服务器,它负责通过SMTP协议管理发送到本机的邮件以及由本机发向外界的邮件。在本例中,Postfix会把邮件的本地投递工作「接受到邮件之后将邮件存档到本地磁盘」交给Dovecot的LMTP服务「Local Mail Transfer Protocol service」处理。当然,当大家想通过服务器向外界发送邮件时,Postfix还将负责验证权限以确保服务器不被滥用。「很多邮件服务器根本没有对SMTP做用户验证,这将导致任何匿名用户都可以通过服务器向外界发送邮件,从而使得服务器变成垃圾中转站。


Dovecot: 是一个非常优秀的IMAP/POP服务器用以接收外界发送到本机的邮件。通常,Dovecot的工作内容包括:验证用户身份以确保邮件不会被泄露。在本例中,Dovecot将负责所有的「身份验证」工作,我们会配置Dovecot查询本地的MySQL数据库以确认用户身份。


基础知识:

/var/log/maillog:                                         邮件日志 所在目录

port:tcp 25                                                邮件开放的端口
postconf -d                                                查看默认设置
postconf -n                                                查看当前设置

postconf -e "inet_interfaces = all"                修改选项

inet_interfaces 参数指定postfix系统监听的网络接口。缺省地,postfix监听 所有的网络接口。如果你的postfix运行在一个虚拟的ip地址上,则必须指定其监听的地址。如: inet_interface = 192.168.1.1

postsuper -d *******                                    删除邮件mailq中的邮件

 
[root@qq log]#mail root@westos.com
   

Subject: westos
hhhh
.              ###用“.”来结束输入内容并发送      
mailq          ###查看邮件队列
postqueeu -f   ###重新处理邮件队列

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

协议            端口
pop3          110    
imap          143
imaps        993
pop3p        995

2.配置

2.1邮件的基本的配置

vim /etc/postfix/main.cf
76 myhostname = westos.mail.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


2.2.邮件别名

 vim /etc/aliases
admin:          root                                                             邮件别名  格式 :  别名: 真名

moreuser:       :include:/etc/postfix/moreuser                      邮件群发

vim  /etc/postfix/moreuser

user1

user2

useradd  user1

useradd  user2

postalias /etc/aliases                                                     刷新别名数据库

测试

[root@qq log]# mail moreuser@westos.com

[root@westos postfix]# mail -u user1

[root@westos postfix]# mail -u user2


[root@dns log]# mail student@qq.com



[root@localhost postfix]# mail -u student


[root@localhost log]# mail admin@westos.com



2.3  远程发送邮件

[root@localhost Desktop]# yum install telnet -y             安装远程登陆程序
[root@localhost Desktop]# telnet 192.168.122.121 25
Trying 192.168.122.121...
Connected to 192.168.122.121.
Escape character is '^]'.
220 westos.mail.com ESMTP Postfix
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>



2.4 邮件的访问控制

[root@qq log]# postconf -d | grep client
[root@qq log]# postconf -e "smtpd_client_restrictions = check_client_access hash:/etc/postfix/access"
[root@qq log]# vim /etc/postfix/access
172.25.254.21  REJECT                                                  拒绝要登陆的远程主机
[root@qq log]# vim /etc/postfix/main.cf
[root@qq log]# postmap /etc/postfix/access
[root@qq log]# systemctl restart postfix.service

测试
[root@localhost Desktop]# telnet 192.168.122.121 25


2.5 限制用户发送

 [root@westos ~]# postconf  -d | grep send                    显示postfix的发送选项
[root@westos ~]# postconf -e "smtpd_sender_restrictions = check_sender_access hash:/etc/postfix/sender"                                                                     设置smtpd_sender_restrictions的值
[root@westos ~]# vim /etc/postfix/sender   
[root@westos ~]# cat /etc/postfix/sender
student@westos.com  REJECT
[root@westos ~]# postmap /etc/postfix/sender  ###加密
[root@westos ~]# systemctl restart postfix.service

测试

[root@localhost Desktop]# telnet 192.168.122.121 25



2.6 限制用户的接受
[root@westos ~]# postconf  -d | grep recipient
[root@westos ~]# postconf -e " smtpd_recipient_restrictions = check_recipient_access hash:/etc/postfix/recip"
[root@westos ~]# vim /etc/postfix/recip
[root@westos ~]# cat /etc/postfix/recip
student@westos.com REJECT
[root@westos ~]# postmap /etc/postfix/recip

[root@westos ~]# systemctl restart postfix.service

测试

[root@localhost Desktop]# telnet 192.168.122.121 25



2.7出站地址伪装
[root@westos ~]# postconf -d | grep generic
[root@westos ~]# postconf -e "smtp_generic_maps = hash:/etc/postfix/geniric"
[root@westos ~]# vim /etc/postfix/geniric
[root@westos named]# vim /etc/postfix/geniric
[root@westos ~]# cat /etc/postfix/geniric
student@westos.com hello@haha.com
[root@westos ~]# postmap /etc/postfix/geniric

[root@westos ~]# systemctl restart postfix.service



测试:

[root@westos ~]# mail root@qq.com


邮件查收



2.8 入站地址伪装

先做dns记录解析

 vim /etc/named.rfc1912.zones

zone "haha.com" IN {
        type master;
        file "haha.com.zone";
        allow-update { none; };
};
[root@westos named]# cat haha.com.zone
$TTL 1D
@    IN SOA    dns.haha.com. root.haha.com. (
                    0    ; serial
                    1D    ; refresh
                    1H    ; retry
                    1W    ; expire
                    3H )    ; minimum
        NS    dns.haha.com.
dns        A    172.25.254.121
haha.com.        MX 1    172.25.254.121.



[root@westos named]# postconf -d | grep virtual
[root@westos named]# postconf -e "virtual_alias_maps = hash:/etc/postfix/virtual"
[root@westos named]# vim /etc/postfix/virtual
hello@haha.com  root@westos.com
[root@westos named]# postmap  /etc/postfix/virtual
[root@westos named]# systemctl restart postfix.service

测试:
[root@qq ~]# mail hello@haha.com

邮件查收


2.9 dovector

[root@westos student]# yum install dovecot -y

[root@westos student]# vim /etc/dovecot/dovecot.conf
 24 protocols = imap pop3 lmtp
48 login_trusted_networks = 0.0.0.0/0
 49 disable_plaintext_auth = no

[root@westos student]# vim /etc/dovecot/conf.d/10-mail.conf
30 mail_location = mbox:~/mail:INBOX=/var/mail/%u

[root@westos student]# systemctl restart dovecot

[root@westos student]# su - student
[student@westos ~]$ mkdir mail/.imap/ -p
[student@westos ~]$ touch mail/.imap/INBOX

[root@westos redhat]# mkdir /etc/skel/mail/.imap -p           可以自动创建文件
[root@westos redhat]# touch /etc/skel/mail/.imap/INBOX
[root@westos redhat]# useradd tom
[root@westos redhat]# echo tom |passwd --stdin tom
测试:

[root@foundation21 Desktop]# mutt -f pop://student@172.25.254.121     邮件用户代理



2.10雷鸟

邮件的图形界面





2.11  postfix+mysql

准备工作
yum install httpd php php-mysql mariadb-server -y         安装相应的软件
systemctl start httpd                                                    开启Apache服务
 vim /etc/my.cnf                                                           配置数据库
 skip-networking=1
systemctl restart mariadb
 mysql_secure_installation                                            数据库安全初始化
tar jxf phpMyAdmin-3.4.0-all-languages.tar.bz2 -C /var/www/html/   安装数据库图形管理界面
mv phpMyAdmin-3.4.0-all-languages mysqladmin

登陆建表


cp config.sample.inc.php config.inc.php
    vim config.inc.php

mysql -uroot -p123
create user postuser@localhost identified by 'postuser';       创建postuser用户
grant select,update,insert on emailuser.* to  postuser@localhost; 为postuser用户授权

select * from emailuser.emailuser;

配置:

[root@westos postfix]# cat mailuser.cf            ###用户名称查询
hosts = localhost                    ##数据库所在主机
user = postuser                        ##登陆数据库的用户
password = postuser                    ##登陆数据库的密码
dbname = emailuser                    ##postfix要查询
table = emailuser
select_field = username

where_field = username



[root@westos postfix]# cat maildomain.cf
hosts = localhost
user = postuser
password = postuser
dbname = emailuser
table = emailuser
select_field = domain
where_field = domain

[root@westos postfix]# cat mailbox.cf
hosts = localhost
user = postuser
password = postuser
dbname = emailuser
table = emailuser
select_field = maidir
where_field = username

[root@westos postfix]# postmap -q "lee@lee.com" mysql:/etc/postfix/mailuser.cf
lee@lee.com
[root@westos postfix]# postmap -q "lee" mysql:/etc/postfix/maildomain.cf
lee
[root@westos postfix]# postmap -q "lee@lee.com" mysql:/etc/postfix/mailbox.cf

/mnt/lee.com/lee/

在主配置文件里会增加如下几行



测试


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值