3

邮箱地址无效导致群发邮件失败

 6 months ago
source link: https://bajie.dev/posts/20240304-posfix_relay/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

邮箱地址无效导致群发邮件失败

2024-03-04 2 分钟阅读

这个问题十分的讨厌啊,Bi大数据部会群发报表邮件,但是如果有某位员工离职了,邮件地址被清理掉不存在了,那么群发邮件的时候会导致群发失败。

网上搜索了一圈,阿里有篇文章是同样问题:

https://blog.csdn.net/javaee_sunny/article/details/114836546

解决方法是修改发送程序,剔除掉失效的邮件地址再发。

这个方法在我们这里是行不通的,因为发送程序没人维护了,无法修改。

那就只能曲线救国了:建立一个转发服务器,把群发邮件变成一封一份单独发,那么偶尔一份失败就失败了,不会导致整个群发的失败。

搭建一个Postfix relay转发服务器:

vi /etc/postfix/main.cf

relayhost = [smtp.qiye.aliyun.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_use_tls = yes
smtp_tls_CAfile = /etc/pki/tls/certs/ca-bundle.crt
smtp_sender_dependent_authentication = yes
smtp_destination_recipient_limit = 1
message_size_limit=102400000

解释:转发到阿里邮件服务器的标准配置,网络上已经有很多教程了。然后关键就一条smtp_destination_recipient_limit = 1,这个就会把群发的邮件拆成单独的一封一封发送,发不出去的会回到queue尝试不断发送,最后失败drop掉。

另外postfix缺省发送邮件的大小是10M,阿里邮局缺省是50M,我们需要修改一下,message_size_limit=102400000改成100M的限制。

最后生成一下邮件用户的hash库:

vi /etc/postfix/sasl_passwd
[smtp.qiye.aliyun.com]:587  [email protected]:xxxxxxxx

postmap /etc/postfix/sasl_passwd

那么发邮件的时候指定这台服务器,用户名是 [email protected] , 密码是xxxxxxxx就可以了

补充,需要安装缺少的库,否则登录阿里邮局过不去,还需要打开服务器的允许网段列表,mynetwork

yum install -y cyrus-sasl-plain

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK