2

Good Morning:

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

Features

  • 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 = "blabla@gmail.com"
$EmailFrom = "blabla@mydomain.com.ar"
$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("blabla@mydomain.com.ar", "pass"); 
$SMTPClient.Send($SMTPMessage)

Tested with Send-MailMessage and same error:

$from = "bla@bla.com.ar" 
$to = "bla@gmail.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!

  • What's the error? – Lenniey Jan 16 at 12:43
  • How do the two VMs connect to the Internet? If they appear to have different public IP addresses, then SPF is very likely the culprit. – Massimo Jan 16 at 12:57
  • No error. Mail not delivered in Win 2016 to external accounts only. Same public IP, same internet conection. What can I investigate on SPF? – jpussacq Jan 16 at 14:02
  • 1
    Is your SMTP server actually listening on port 26 or is that a typo? Also, have you read the documentation on the SmtpClient (docs.microsoft.com/en-us/dotnet/api/…) Looks like the API is now obsolete. They are recommending a couple other options, one being github.com/jstedfast/MailKit – Tim Liston Jan 16 at 15:29
  • 1
    Your script does not even appear to be checking for the error. – Michael Hampton Jan 16 at 15:45
0

Finally I have solved the problem by changing the name of the computer. After looking for differences between the VMs, I noticed checking the headers of the emails, that the name of the computer appeared in the header. I changed it and it started to work. As if in some way, that name would be blocked ...

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.