Intuition
Intuition

Reputation: 13

Send-MailMessage command in a single line not working

I am trying to make a single line Send-MailMessage command. I came out with this code:

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)))

And I got this error:

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

Please help me!!

Upvotes: 1

Views: 892

Answers (1)

John Donnelly
John Donnelly

Reputation: 917

The Port parameter did not appear until PowerShell V 3.0. Download and install the latest Windows Management Framework and try it.

Upvotes: 3

Related Questions