2017-11-18 57 views
1

我正在嘗試使單行Send-MailMessage命令。我想出了這個代碼:Send-MailMessage命令在單行不起作用

Send-MailMessage -SmtpServer 'smtp.gmail.com' -Port 587 -From '[email protected]' -To '[email protected]' -Subject 'Test' -Body 'Body' -UseSsl -Credential (New-Object System.Management.Automation.PSCredential('[email protected]', (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 '[email protected]' -To '[email protected]' -Subject 'Test' -Body 'Body' -UseSsl -Credential (New-Object system.Management.Automation.PSCredential('[email protected]', (ConvertTo-SecureString 'my_password' -AsPlainText -Force))) 
+ CategoryInfo   : InvalidArgument: (:) [Send-MailMessage], ParameterBindingException 
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.SendMailMessage 

請幫助我!

回答

3

直到PowerShell V 3.0之後才顯示Port參數。下載並安裝最新的Windows Management Framework並嘗試它。