解决send-MailMessage SMTP验证发送时的弹出窗口

本文介绍了一种在SMTP服务器禁止匿名发送邮件时的解决方案。通过使用-credential参数结合Powershell命令,可以实现邮件的有效认证并成功发送。该方法通过创建安全字符串和凭据对象来绕过交互式密码输入。

大家在使用send-mailmessge 编写一些脚本的时候一般会使用匿名发送的方式,如下所示:

send-mailmessage -to "test@contoso.com" -from "test@contoso.com" -subject "mailtest" -SmtpServer mail.contoso.com

但是在smtpserver禁止匿名发送的情况下,应该怎么办呢?好多人说可以调用-credential参数。

但是在控制台默认输入-credential一般会弹出窗口提示输入密码,没办法调用到脚本里。有没有一种法可以将密码进行处理呢?

举例说明:

$password = convertto-securestring "password.2013" -asplaintext -force
$cred=new-object -typename System.Management.Automation.PSCredential -argumentlist "test",$password
send-mailmessage -to "test@contoso.com" -from "test@contoso.com" -subject "mailtest" -credential $cred -SmtpServer mail.contoso.com

这样可以很完美的调用一个使用SMTP验证的邮件发送脚本。



本文转自handsome7038 51CTO博客,原文链接:http://blog.51cto.com/lixiaosong/1322643

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值