通过Powershell检查SMTP地址是否被检测网站列入黑名单

  通常,我们可能因为某些用户发送了一些非常规邮件,邮件出口地址被一些权威网站列入黑名单,导致大量业务邮件无法正常发送。
这时候,我们可以通过powershell写一些关于IP地址检测的脚本,并列入计划任务,最大程度上降低邮件出口地址被列入黑名单产生的
业务影响,脚本内容如下:

#获取页面信息
$web=(Invoke-WebRequest "https://www.talosintelligence.com/reputation_center/lookup?search=xxx.xxx.xxx.xxx").content

#自定义邮件属性&内容
$msg1="xxx.xxx.xxx.xxx blacklist, Please check!"
$msg2="Mailaddress is not included in the blacklist!"
$smtp="smtp server"br/>$from="xxx@contoso.com"
$to="xxx@contoso.com"
br/>$cc="xxx@contoso.com"
$body="Smtp address in the blacklist,Please access 
http://www.spamhaus.org Remove!"
$body1="Smtp address is OK!"

#判断IP地址是否被Black
if ($web -match '<span class="blacklisted">Listed</span>' )
{ Send-MailMessage -Subject $msg1 -SmtpServer $smtp -From $from -to $to -cc $cc -Body $body
}

else
{ Send-MailMessage -Subject $msg2 -SmtpServer $smtp -From $from -to $to -cc $cc -Body "$body1"
}

 

  以上初步完成了SMTP地址的检测目的,但是这里会有一个小坑,脚本会报错“Invoke-WebRequest : 请求被中止: 未

能创建 SSL/TLS 安全通道”,经过各种资料查找,发现需要设置安全协议版本为TLS1.2,.net下只需要添加如下一条代码

即可:

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

 

Powershell中需要做一些变化,如下:

    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12(添加到脚本第一行即可)

 

转载于:https://www.cnblogs.com/zhr1217/p/9685855.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值