海运的博客

PVE/postfix配置smtp发送邮件

发布时间:December 9, 2021 // 分类: // No Comments

安装认证模块:

apt install libsasl2-modules
#如需pcre匹配安装
#apt install postfix-pcre

修改/etc/postfix/main.cf添加:

myhostname=pve.lan
#配置文件内有relayhost要先注释,465端口是SMTPS,587端口是STARTTLS
relayhost = smtp.qq.com:465

#此参数被smtp_tls_security_level取代
#smtp_use_tls = yes
#使用SMTPS非STARTTLS加密方式
smtp_tls_wrappermode = yes
#加密级别
smtp_tls_security_level = encrypt
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous

#本地用户替换为smtp认证用户,smtp_generic_maps和sender_canonical_maps都可以
smtp_generic_maps = hash:/etc/postfix/generic
#sender_canonical_maps = hash:/etc/postfix/sender_canonical
#使用pcre匹配本机用户
#sender_canonical_maps = pcre:/etc/postfix/sender_pcre_canonical
#header检查并替换发送者名称
smtp_header_checks = pcre:/etc/postfix/smtp_header_checks

sender_canonical或generic映射本机用户到smtp账号:

cat /etc/postfix/generic
#本机所有用户,注意pve.lan为主配置文件myhostname
@pve.lan support@haiyun.me
#下面2个等效
root support@haiyun.me
root@pve.lan support@haiyun.me

正则映射:

cat /etc/postfix/sender_pcre_canonical
#匹配所有hostname和所有用户
/.*/ support@haiyun.me

smtp账号密码:

cat /etc/postfix/sasl_passwd
smtp.qq.com support@haiyun.me:password

生成hash数据库,pcre不用生成:

postmap /etc/postfix/sasl_passwd
postmap /etc/postfix/generic
postmap /etc/postfix/sender_canonical

替换发件人姓名:

cat /etc/postfix/smtp_header_checks 
/^From:.*/ REPLACE From: 重要通知 <support@haiyun.me>

发送邮件测试:

apt install bsd-mailx
echo "www.haiyun.me" |mail -s test support@haiyun.me
echo "test" | /usr/bin/pvemailforward

将其它用户邮件转发到root用户:

cat /etc/aliases
postmaster: root
nobody: root
#也可使用~/.forward 
#root: support@haiyun.me
postalias /etc/aliases

将root用户邮件转发到外部邮箱:

cat ~/.forward 
support@haiyun.me

参考:
https://serverfault.com/questions/717719/how-can-i-strip-or-rewrite-the-senders-name-of-a-from-address-when-using-postfi
https://forum.proxmox.com/threads/get-postfix-to-send-notifications-email-externally.59940/

此内容被密码保护

发布时间:November 20, 2013 // 分类:Mail // No Comments

请输入密码访问

Bind为域名邮箱添加SPF记录

发布时间:August 25, 2012 // 分类:Mail // No Comments

在垃圾邮件泛滥的今天,邮件服务器和域名设置SPF是必不可少的,之前有介绍PostFix下配置SPF验证,那怎么能证明自己服务器发出的邮件能被对方视为来源正确呢,那就为自己的域名添加SPF记录吧。
SPF记录以TXT格式配置在DNS中,可以使用以下参数定义信任地址:

include #调用特定域名的SPF进行验证
ip4 #使用 IPv4 进行验证
ip6 #使用 IPv6 进行验证
a  #使用域名A记录验证
mx #使用MX记录验证
ptr #使用PTR进行验证

定义匹配时的返回值:

+ #默认,通过
- #硬失败
~ #软失败
? #不置可否

SPF书写示例:

"v=spf1 +a:www.haiyun.me +ip4:192.168.1.0/24 -all"
#定义www.haiyun.me的A记录IP和192.168.1.0/24网段,其它全部为不信任,+默认可略。

将域名SPF添加到BIND DNS服务器

@       IN      TXT     "v=spf1 a ip4:184.164.141.188 ~all"
#或
www.haiyun.me.      IN      TXT     "v=spf1 a ip4:184.164.141.188 ~all"

测试SPF是否生效:

dig www.haiyun.me txt +short
"v=spf1 a ip4:184.164.141.188 ~all"

也可以发送到gmail邮箱查看SPF验证结果:

Received-SPF: pass (google.com: domain of admin@www.haiyun.me designates 184.164.141.188 as permitted sender) client-ip=184.164.141.188;
Authentication-Results: mx.google.com; spf=pass (google.com: domain of admin@www.haiyun.me designates 184.164.141.188 as permitted sender) smtp.mail=admin@www.haiyun.me

Postfix配置SPF防发件人欺骗

发布时间:July 11, 2012 // 分类:Mail // No Comments

之前有介绍Postfix服务器在转发授权用户邮件时防止发件人伪造,如果在接收邮件时怎么确认收到的邮件发件人是真实的呢?这个就要靠SPF的帮忙了。
当服务器接收到邮件时会检查域名的SPF记录与客户端IP是否匹配,如匹配就被认为是真实的邮件,不匹配就被认为是假冒的邮件,当然如果对方域名未做SPF记录会被误报。
安装postfix-policyd-spf-perl用以检查域SPF记录并匹配:

#https://www.haiyun.me
yum install perl-Mail-SPF perl-Sys-Hostname-Long
wget https://launchpad.net/postfix-policyd-spf-perl/trunk/release2.010/+download/postfix-policyd-spf-perl-2.010.tar.gz
tar zxvf postfix-policyd-spf-perl-2.010.tar.gz 
mv postfix-policyd-spf-perl-2.010/postfix-policyd-spf-perl /usr/sbin/
chmod +x /usr/sbin/postfix-policyd-spf-perl

开启postfix-policyd-spf-perl服务:

cat /etc/postfix/master.cf
policy-spf  unix  -       n       n       -       -       spawn
     user=nobody argv=/usr/sbin/postfix-policyd-spf-perl

编辑Postfix主配置文件添加SPF过滤规则:

cat /etc/postfix/main.cf
smtpd_recipient_restrictions =
     permit_mynetworks,
     permit_sasl_authenticated,
     reject_unauth_destination,
     #reject_unknown_client,
     check_policy_service unix:private/policy-spf

重新加载Postfix配置文件:

/etc/init.d/postfix reload

测试SPF效果:

#下为错误
postfix/policy-spf[15857]: Policy action=PREPEND Received-SPF: softfail (www.haiyun.me: Sender is not authorized by default
#下为正确
postfix/policy-spf[15726]: Policy action=PREPEND Received-SPF: pass (qq.com: Sender is authorized to use 'qq@qq.com'

Policy-spy默认不阻止验证失败的发件人邮件,会在邮件头部添加Received-SPF: softfail标签,如果要对其处理可使用Postfix过滤规则header_checks进行匹配操作。
添加header_checks匹配规则:

cat /etc/postfix/header_checks 
/Received-SPF: softfail/   REJECT

编辑主Postfix主配置文件应用此规则:

cat main.cf
header_checks = pcre:/etc/postfix/header_checks

再次测试效果:

postfix/cleanup[15865]: A3A6410C005D: reject: header Received-SPF: softfail

Postfix过滤限制参数

发布时间:July 11, 2012 // 分类:Mail // No Comments

根据SMTP协议流程Postfix可在以下规则内对客户端信息进行限制:

#https://www.haiyun.me
smtpd_client_restrictions = 
#客户端连接后匹配登录IP、反向查询在此匹配
smtpd_helo_restrictions = 
#客户端连接后以HELO显示送信方主机名称在此限制。
smtpd_sender_restrictions = 
#寄件人名称限制
smtpd_recipient_restrictions = 
#收件人名称限制
smtpd_data_restrictions = 
#内容限制,分header_check和check_body

Postfix过滤限制规则:
1.客户端SMTP连接时过滤:

smtpd_client_restrictions = 
     check_client_access = type:map #检查匹配表操作
     reject_rbl_client = #针对IP黑名单
     reject_rhsbl_client = #针对IP黑名单
     reject_unknown_client #拒绝客户地址没有反解及对应A记录

2.HELO阶段过滤:

smtpd_helo_restrictions = 
     check_helo_access = type:map #检查匹配表操作
     permit_naked_ip_address #允许直接使用ip地址的连接
     reject_invalid_hostname #拒绝无效格式的主机名
     reject_unknown_hostname  #拒绝未知的主机名连接,即无有效A或MX记录
     reject_no_fqdn_hostname #拒绝主机名非FQDN格式

3.发件人过滤,可在此限制Postfix发件人欺骗

smtpd_sender_restrictions = 
     check_sender_access = type:map #检查匹配表操作
     reject_no_fqdn_sender #拒绝发件人非FQDN格式
     reject_rhsbl_sender = #发件人黑名单
     reject_unknown_sender_domain  #拒绝未知的发件人域,即无有效A或MX记录
     reject_sender_login_mismatch #拒绝登录用户与发件人不匹配

4.收件人过滤:

smtpd_recipient_restrictions = 
     check_recipient_access = type:map #检查匹配表操作
     permit_mynetworks      #mynetworks用户通过,匹配结束
     permit_sasl_authenticated  #sasl验证用户通过,匹配结束
     reject_unauth_destination #拒绝收件人非mydestination、relay_domains或virtual_alias_maps定义域邮件
     reject_no_fqdn_recipient  #拒绝收件人非FQDN格式
     reject_rhsbl_recipient = #收件人黑名单
     reject_unknown_recipient_domain  #拒绝未知的收件人域,即无有效A或MX记录

5.邮件内容过滤:

header_checks = pcre:/etc/postfix/header_checks
mime_header_checks = pcre:/etc/postfix/mime_header_checks
nested_header_checks = pcre:/etc/postfix/nested_header_checks
body_checks = pcre:/etc/postfix/body_checks
分类
最新文章
最近回复
  • 海运: 恩山有很多。
  • swsend: 大佬可以分享一下固件吗,谢谢。
  • Jimmy: 方法一 nghtp3步骤需要改成如下才能编译成功: git clone https://git...
  • 海运: 地址格式和udpxy一样,udpxy和msd_lite能用这个就能用。
  • 1: 怎么用 编译后的程序在家里路由器内任意一台设备上运行就可以吗?比如笔记本电脑 m参数是笔记本的...
  • 孤狼: ups_status_set: seems that UPS [BK650M2-CH] is ...
  • 孤狼: 擦。。。。apcupsd会失联 nut在冲到到100的时候会ONBATT进入关机状态,我想想办...
  • 海运: 网络,找到相应的url编辑重发请求,firefox有此功能,其它未知。
  • knetxp: 用浏览器F12网络拦截或监听后编辑重发请求,修改url中的set为set_super,将POS...
  • Albert: 啊啊啊啊啊啊啊啊啊 我太激动了,终于好了英文区搜索了半天,翻遍了 pve 论坛没找到好方法,博...