I'm running exactly the same script from two different virtual machines:
- The first in Windows Server 2008 R2
- The second in Windows Server 2016
- The SMTP is an external service of a hosting (BlueHost)
- The script does not generate an error
- The mail arrives in both cases to internal addresses (from BlueHost)
- The mail does not reach external addresses (like gmail) in the second case (Win 2016)
- Both VMs run on the same desktop
- Both VMs have antivirus and Firewall disabled
I'm looking for help to understand where the problem is. I think there is some strange configuration in Windows 2016 that causes BlueHost to block it or Gmail does not receive it.
I have tried many things, but I arrived at a very strange point, in which I do not understand what happens.
This is the script I use to test, only for test purposes. Since the same error is generated by sending the email from SQL Server Databasemail.
$EmailTo = "email@example.com" $EmailFrom = "firstname.lastname@example.org" $Subject = "Test a" $Body = "Test Body" $SMTPServer = "mail.mydomain.com.ar" $SMTPMessage = New-Object System.Net.Mail.MailMessage($EmailFrom,$EmailTo,$Subject,$Body) $SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 26) $SMTPClient.EnableSsl = $false $SMTPClient.Credentials = New-Object System.Net.NetworkCredential("email@example.com", "pass"); $SMTPClient.Send($SMTPMessage)
Tested with Send-MailMessage and same error:
$from = "firstname.lastname@example.org" $to = "email@example.com" $smtp = "mail.bla.com.ar" $sub = "hi" $body = "test mail 2" $secpasswd = ConvertTo-SecureString "pass" -AsPlainText -Force $mycreds = New-Object System.Management.Automation.PSCredential($from, $secpasswd) Send-MailMessage -To $to -From $from -Subject $sub -Body $body -Credential $mycreds -SmtpServer $smtp -DeliveryNotificationOption Never -BodyAsHtml -Port 26
Some help? Thanks since now!