Wednesday 6 January 2016

The SMTP server requires a secure connection or the client was not authenticated in powershell.

Exception calling "Send" with "1" argument(s): "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Require
d. Learn more at"
At C:\Users\asishm\Desktop\JDRPowershell_Scripts\Mail.ps1:12 char:11
+ $smtp.Send <<<< ($SMTPMessage)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException


Solution:

Go to the below site url to enable the "Access for less secure apps".

https://www.google.com/settings/security/lesssecureapps


It will work 100%.

Tuesday 5 January 2016

How to Send SMTP Email using Powershell

$smtpServer = "smtp.gmail.com"
$smtpFrom = "abc@gmail.com"
$smtpTo = "xyz@gmail.com"
$messageSubject = "Dropped ping report"

[string]$messagebody = "Hi Hello"

$smtp = New-Object Net.Mail.SmtpClient($smtpServer,587)

$smtp.EnableSsl = $true 

$smtp.Credentials = New-Object System.Net.NetworkCredential("Gmail Username", "Password")

$SMTPMessage = New-Object 
System.Net.Mail.MailMessage($smtpFrom,$smtpTo,$messagesubject,$messagebody)

$smtp.Send($SMTPMessage)