Reputation: 2357
I'm writing a Powershell email feature, I used comdle
"Send-MailMessage -To mail -From mail -Subject"
I'm getting the error:
Unable to connect to the remote server.
Also, I wonder if this method works?
New-Object System.Net.Mail.MailMessage($From, $To, $Subject, $Body)
and what's the difference with Send-MailMessage?
Upvotes: 0
Views: 565
Reputation: 313
At first, you need to check your SMTP and see if you can parse or ping your SMTP server. Also, Have you checked your port e.g. 587 ? Like this:
Send-MailMessage -To $to -From $from -cc $cc -Subject $sub -Body $body -Credential $mycreds -SmtpServer $smtp -DeliveryNotificationOption Never -BodyAsHtml -UseSsl -port 587
For the send email difference, you can also refer to the following link:
Scripting: Send email using Powershell and System.Net.Mail API
Upvotes: 1