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

简介:

大家在使用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

相关文章
关于basp21发送邮件需要smtp验证的问题。
% response.write("") Set bobj = Server.CreateObject("basp21") ' ASP response.write(bobj.
1180 0
|
4月前
|
Python
python使用smtp发送邮件
python使用smtp发送邮件
62 0
|
6月前
|
数据安全/隐私保护
【Azure Logic App】在Azure Logic App中使用SMTP发送邮件示例
【Azure Logic App】在Azure Logic App中使用SMTP发送邮件示例
|
7月前
|
JavaScript API PHP
不用SMTP实现联系表单提交后发送邮件到指定邮箱
构建网站时,联系表单可通过邮件API(如SendGrid、Mailgun、Amazon SES)或第三方自动化服务(Zapier、Integromat)无需SMTP发送邮件。这些服务提供API接口和自动化工作流程,简化邮件发送。例如,使用SendGrid API在Python中发送邮件涉及注册、获取API密钥并编写发送邮件的代码。同样,Zapier可作为表单提交的触发器,自动发送邮件。此外,后端脚本(如PHPMailer)也能实现这一功能,但需编写处理SMTP的代码。选择适合的方法能优化邮件发送流程。
|
8月前
|
网络安全 数据安全/隐私保护 Python
Python SMTP发送邮件
Python SMTP发送邮件
|
9月前
|
API 网络安全 数据安全/隐私保护
SMTP邮件邮箱API发送邮件的方法和步骤
使用SMTP邮件邮箱API(如AokSend)发送邮件涉及6个步骤:获取SMTP服务器地址和端口,进行身份验证,构建邮件内容,连接到服务器,发送邮件及处理结果。例如,Gmail的SMTP服务器地址是smtp.gmail.com,端口587。此方法适用于程序化发送邮件,确保安全并支持大规模发信服务。
|
9月前
|
Ruby
|
9月前
|
数据安全/隐私保护 Ruby
|
9月前
|
数据安全/隐私保护 Ruby