Send-MailMessage命令在单行中不起作用

时间:2017-11-18 03:30:49

标签: powershell sendmessage

我正在尝试制作一行Send-MailMessage命令。我出来了这段代码:

Send-MailMessage -SmtpServer 'smtp.gmail.com' -Port 587 -From 'my_email@gmail.com' -To 'someone_email@gmail.com' -Subject 'Test' -Body 'Body' -UseSsl -Credential (New-Object System.Management.Automation.PSCredential('my_email@gmail.com', (ConvertTo-SecureString 'my_pass' -AsPlainText -Force)))

我收到了这个错误:

Send-MailMessage : A parameter cannot be found that matches parameter name 'Port'.
At G:\Send_email\TEST-SEND-EMAIL.ps1:1 char:23
+ Send-MailMessage -Port <<<<  587 -SmtpServer 'smtp.gmail.com' -From 'my_email@gmail.com' -To 'someone_email@gmail.com' -Subject 'Test' -Body 'Body' -UseSsl -Credential (New-Object system.Management.Automation.PSCredential('my_email@gmail.com', (ConvertTo-SecureString 'my_password' -AsPlainText -Force)))
+ CategoryInfo          : InvalidArgument: (:) [Send-MailMessage], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.SendMailMessage

请帮助我!!

1 个答案:

答案 0 :(得分:3)

在PowerShell V 3.0之前,Port参数才出现。下载并安装最新的Windows Management Framework并进行试用。