在PowerShell中,如何配置smtpserver:
ping "stmp.email.com" = “xxx.xx.xx.xxx”
$smtpServer = “xxx.xx.xx.xxx” or "stmp.email.com"????????
PS代码:
$IPsmtp = 'xxx.xx.xx.xxx'
$PlainPassword = "adminpassword"
$SecurePassword = $PlainPassword | ConvertTo-SecureString -AsPlainText -Force
$Username = "MYSITE\Administrator"
$Credentials = New-Object System.Management.Automation.PSCredential -ArgumentList $Username, $SecurePassword
$mailprops=@{
Subject = 'This Subject'
Body = 'The Body and the subBody'
To = 'emailto@mail.com'
From = 'emailfrom@email.com'
SmtpServer = 'smtp.email.com'
}
Send-MailMessage $mailprops -Credential $Credentials
无论我是否使用SmtpServer:'smtp.email.com'或$ IPsmtp,我仍然会得到相同的结果。
此ps代码缺少'mmp.email.com'的凭据。它有一个与之关联的用户名和密码,但无处输入。
错误代码:
Send-MailMessage : The specified string is not in the form required for an e-mail address.
At C:\Users\Administrator\Documents\ps\Email.ps1:14 char:1
+ Send-MailMessage $mailprops -Credential $Credentials
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidType: (:) [Send-MailMessage], FormatException
+ FullyQualifiedErrorId : FormatException,Microsoft.PowerShell.Commands.SendMailMessage
Send-MailMessage : The email cannot be sent because no SMTP server was specified. You must specify an SMTP server by
using either the SmtpServer parameter or the $PSEmailServer variable.
At C:\Users\Administrator\Documents\ps\Email.ps1:14 char:1
+ Send-MailMessage $mailprops -Credential $Credentials
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Send-MailMessage], InvalidOperationException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.SendMailMessage