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!

jpussacq
  • 131
  • 6
  • What's the error? – Lenniey Jan 16 '19 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 '19 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 '19 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 (https://docs.microsoft.com/en-us/dotnet/api/system.net.mail.smtpclient?view=netframework-4.7.2) Looks like the API is now obsolete. They are recommending a couple other options, one being https://github.com/jstedfast/MailKit – Tim Liston Jan 16 '19 at 15:29
  • 1
    Your script does not even appear to be checking for the error. – Michael Hampton Jan 16 '19 at 15:45
  • Thanks Tim & Michael. Yes, port 26 is OK. ¿Have you got any power shell script recomendation to make a simple email test? Witch error check and no obsolete API? – jpussacq Jan 16 '19 at 19:17
  • Added script not obsolete with Send-MailMessage – jpussacq Jan 17 '19 at 13:05

1 Answers1

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 ...

jpussacq
  • 131
  • 6