linux运维-postfix邮件的处理
postfix
定义:提供smtp协议用来投递邮件,默认端口25
重置两台虚拟机,配置yum源及正向解析
1.发送邮件
mail [email protected]
Subject: hello
hello world
. ##用“.”来结束录入内容并发送
mailq ##查看邮件队列
postqueue -f ##重新处理邮件队列
postsuper -d ##删除邮件队列
mail ##查看邮件
默认情况下邮件端口只在127.0.0.1上开启
2.配置
vim /etc/postfix/main.cf
76 myhstname = westos-mail.westos.com ##指定mta主机名
83 mydomain = westos.com ##指定mta域名
99 myorigin = westos.com ##指定邮件来源结尾(@后面的内容)
116 inet_interfaces = all ##25端开启的网络接口
164 mydestination = $myhostname,$mydomain, localhost ##接收邮件结尾字符的指定
systemctl restartpostfix.service
systemctl stop firewalld
3.邮件别名
设置别名:
qq:
vim /etc/aliases
别名: 真名
postalias /etc/aliases ##重新读取配置文件
westos:
mail [email protected]
测试:
群发邮件:
qq:
vim /etc/aliases
moreuser: :include:/etc/postfix/moreuser
postalias /etc/aliases
vim /etc/postfix/moreuser
westos:
mail [email protected]
4.远程发送邮件:
telnet 172.25.254.122 25 ##连接到122的25端口
Trying 172.25.254.122...
Connected to 172.25.254.122.
Escape character is '^]'.
220 westos-mail.westos.com ESMTPPostfix
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>
cndkjsfnhvkjnfdkjgnrejne ##邮件内容
.
250 2.0.0 Ok: queued as 8956D246244
quit
221 2.0.0 Bye
Connection closed by foreignhost.
5.邮件客户端的访问控制:
在mta上:
postconf -e"smtpd_client_restrictions = check_client_accesshash:/etc/postfix/access" ##更改postfix默认配置,增加客户端的访问控制,将被限制访问的客户端写入/etc/postfix/access中
vim /etc/postfix/main.cf ##检查主配置文件是否添加了访问控制
vim /etc/postfix/access ##将拒绝连接的客户端写入此配置文件
172.25.254.22 REJECT
postmap /etc/postfix/access ##加密/etc/postfix/access文件
systemctl restart postfix ##重启服务
测试:
6.限制用户发送:(只能接受不能发送)
postconf -d |grep sender
postconf -e “smtpd_sender_restrictions= check_sender_access hash:/etc/postfix/sender” ##更改postfix配置,限制用户发送邮件,将被限制的用户名将被写入/etc/postfix/sender中
vim /etc/postfix/main.cf ##检查主配置文件是否添加了用户限制
vim /etc/postfix/sender ##将被限制的用户名写入此文件中
[email protected] REJECT
postmap /etc/postfix/sender ##加密/etc/postfix/sender文件
systemctl restart postfix ##重启服务
测试:
7.限制用户接受:(只能发送不能接受)
postconf -e"smtpd_recipient_restrictions = check_recipient_accesshash:/etc/postfix/recip" ##更改postfix配置,限制用户接受邮件,将被限制的用户名将被写入/etc/postfix/recip中
vim /etc/postfix/main.cf ##检查主配置文件是否添加了用户限制
vim /etc/postfix/recip ##将被限制接受的用户写入此文件中
[email protected] REJECT
postmap /etc/postfix/recip ##加密/etc/postfix/recip文件
systemctl restart postfix ##重启服务
测试:
8.出站伪装
postconf -e "smtp_generic_maps =hash:/etc/postfix/generic"
vim /etc/postfix/main.cf ##检查主配置文件是否添加了出战伪装
vim /etc/postfix/generic
真实地址 伪装地址
[email protected] [email protected]
postmap /etc/postfix/gemeric
systemctl restart postfix
测试:
9.入站地址转换
dns mx 将伪装地址的域的记录解析先做好
vim /etc/named.rfc1912.zones ##增加girl.com的正向解析
cd /var/named
ls
cp -p westos.com.zonegirl.com.zone
postconf -e "virtual_alias_maps =hash:/etc/postfix/virt"
vim /etc/postfix/virt
虚拟名字 真实用户
[email protected] [email protected]
postmap /etc/postfix/virt
systemctl restart postfix
测试: