I am trying to send an email via SMTP using powershell.
I have stored these variables in config.ps1 file
$smtpServer = "10.0.52.10"
$emailFrom = "prudhvi.g@xiomi.com"
$emailTo = "prudhvi@gmail.com"
$emailsubject = "Health Check"
$emailbody = "Hi"
This is my script to send email :
##################################################
#Send email with results
##################################################
. .\config.ps1
foreach ($line in $bodystring)
{
$emailbody = $emailbody + $line + "`r`n"
}
Send-MailMessage -To "$emailTo" -From "$emailFrom" -smtpServer "$smtpserver" -subject "$emailsubject" -body "$emailbody"
I get this error :
Send-MailMessage : Unable to connect to the remote server
At C:\Users\administrator.SDC\Desktop\email.ps1:12 char:1
+ Send-MailMessage -To "$emailTo" -From "$emailFrom" -smtpServer "$smtpserver" -su ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpExcept
ion
+ FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage
What is my mistake?? Should I include something else to make it work?