Executed as user: NT Service\SQLSERVERAGENT. Exception calling "Send" with "1" argument(s): "Failure sending mail."

Viewed 31

I've want to send mail from SQL Server. I have tried with Google account with the below mentioned Windows PowerShell Codes and it's been working perfectly.

Google account script:

$EmailTo = "xxxxxxx@gmail.com"
$EmailFrom = "xxxxxxx@gmail.com"
$Subject = "Test"
$Body = "Test Body"
$SMTPServer = "smtp.gmail.com"
$SMTPMessage = New-Object System.Net.Mail.MailMessage($EmailFrom,$EmailTo,$Subject,$Body)
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential("xxxxxxx@gmail.com", "MyPassword"); 
$SMTPClient.Send($SMTPMessage)

but I have need to change the script to my office email id (microsoft account id), So I've changed the script as I written below and and It's also working perfectly.

Microsoft account script (Outlook):

$EmailTo = "xxxxxxxxx@office.co.in"
$EmailFrom = "xxxxxxxxx@office.co.in"
$Subject = "Test"
$Body = "Test Body"
$SMTPServer = "smtp.office365.com"
$SMTPMessage = New-Object System.Net.Mail.MailMessage($EmailFrom,$EmailTo,$Subject,$Body)
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential("xxxxxxxxx@office.co.in", "MyPassword"); 
$SMTPClient.Send($SMTPMessage)

Whenever I tried this code on my machine it's working fine, but I shared the same code to office machine. The Google account code working fine and I received the mails too. But the Microsoft account code is not working properly it gives some errors and not able to receive the mail.

Error:

Executed as user: NT Service\SQLSERVERAGENT. Exception calling "Send" with "1" argument(s): "Failure sending mail."

0 Answers
Related