Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 29762

Can't connect to server with send-MailMessage in Powershell

$
0
0

I have been trying to create an email which will be sent from a gmail account when a PoweShell file is run. However I am unable to connect to the server when using the send-MailMessage method. I have the following code:

$from = "blondedavid@gmail.com"
$to = "blondedavid@gmail.com"
$subject = "The subject of your email"
$body = "This is just a test mail to verify the working of CMD"
$attachment = "C:\Users\37.csv"
$smtp = "smtp.gmail.com"
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential("blondedavid@gmail.com", "xxx");

send-MailMessage -SmtpServer $smtp -Credential $SMTPClient -To $to -From $from -Subject $subject -Body $body -Attachment $attachment -Priority high 

Any help would be greatly appreciated.


Viewing all articles
Browse latest Browse all 29762

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>