I am using the send-MailMessage
cmdlet in PowerShell version 2 and it gives me a error.
I tried using all the options which were mentioned in the earlier posts and it didn't help me.
This is the command that I am using:
send-MailMessage -from "abc@gmail.com" -to "def@gmail.com"
-subject "test" -body"test" -smtp "smtp.gmail.com"
I get an error:
Send-MailMessage : The SMTP server requires a secure connection or the client was not authenticated
e was: 5.7.0 Must issue a STARTTLS command first. l46sm12283804qgd.27 - gsmtp
At line:1 char:17
+ send-MailMessage <<<< -from "abc@gmail.com" -to "def@gmail.com" -subject "te
credential abc
+ CategoryInfo : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Se
ion
+ FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage
I tried using UseSsl= true
and also by giving credentials and even then I was not able to send email. Could you let me know what I am missing here?
In order to use gmail you need SSL, I'am not sure you can use
Send-MailMessage
try this :Edited :
To use mail attachment please have a look Sytem.Net.Mail.MailMessage documentation. You need first to create an Attachment and then to add it to the MailMessage
Attacments
collection.For those that come later, here is my two liner example, for the account "gmail-user@gmail.com". This can be scheduled.