尝试将邮件发送到Office 365时,Send-MailMessage中没有端口参数?

lee*_*d00 3 email parameters powershell

这是我使用的Powershell版本:

$ PSVersionTable.PSVersion产生:

Major  Minor  Build  Revision
-----  -----  -----  --------
2      0      -1     -1
Run Code Online (Sandbox Code Playgroud)

这是命令:

Send-MailMessage -To "someadmin@somedomain.com" -Body "This is just a test"  -Subject "Test"  -UseSsl
 -Port 587 -SmtpServer 'smtp.office365.com' -From 'someadmin@somedomain.com' -Credential $creds
Run Code Online (Sandbox Code Playgroud)

这是错误:

Send-MailMessage : A parameter cannot be found that matches parameter name 'Port'.
At line:1 char:105
+ Send-MailMessage -To "someadmin@somedomain.com" -Body "This is just a test"  -Subject "Test"  -UseSsl -Port <<<<  587 -S
mtpServer 'smtp.office365.com' -From 'someadmin@somedomain.com' -Credential $creds
    + CategoryInfo          : InvalidArgument: (:) [Send-MailMessage], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.SendMailMessage
Run Code Online (Sandbox Code Playgroud)

Port在那个版本的Powershell中是否有争论?我需要升级powershell才能使用它吗?

Pau*_*aul 5

是的,该-Port参数仅在Powershell 3.0及更高版本中可用。

资料来源:Microsoft文档