Unable to send E Mails using powershell

For several years I have been sending messages to myself as reminders. Some I send by Powershell and some I send using Blat which is a utility that automatically sends emails using SMTP protocol. Everything was working fine until about 6 weeks ago when all the emails stopped. I have been looking into the PowerShell scripts to see if I could figure out what the problem is. Shown below is a simple PowerShell that I have been running but still no emails.

$EmailTo = “abc@hotmail.com
$EmailFrom = “abc@hotmail.com
$Subject = “test”
$Body = “This is a test”
$SMTPServer = “smtp-mail.outlook.com

$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential(“abc@hotmail.com”, “xyz”);

$SMTPClient.Send($EmailFrom, $EmailTo, $Subject,$body)

This script runs fine with no errors but still no email. I have eliminated the firewall as the problem. I have used the “Start Transcript” cmdlet but it was not helpful. I have gone through the windows logs but didn’t find anything. I have also used the “Send MailMessage” cmdlet which also runs fine but no email.

philp,
Welcome to the forum. :wave:t4:

Something must have changed. :man_shrugging:t4: If you did not change your code something external has changed. :wink: You may check the log of the mail server.

… and no error message either? You may try the parameter -Verbose

Regardless of that … When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in PowerShell.org <---- Click :point_up_2:t4: :wink:

$EmailTo = “abc@hotmail.com”
$EmailFrom = “abc@hotmail.com”
$Subject = “test”
$Body = “This is a test”
$SMTPServer = “smtp-mail.outlook.com”

$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential(“abc@hotmail.com”, “xyz”);

$SMTPClient.Send($EmailFrom, $EmailTo, $Subject,$body)

Above is the formatted code.
I posted this message before I had finished. Anyway I still don’t know if my problem is local or some place on the internet. Any ideas would be greatly appreciated.

I know that when using Gmail, you need to set an app password to relay SMTP. I suspect maybe M$ has done the same with outlook.com? Here is a link that might get you started:

1 Like

I looked into the app password but I don’t think it would apply here. I don’t use 2-step verification and also this was all working fine until about 6 weeks ago.
Going down a different path- I was able to capture the PS execution posted above using Wireshark. I know very little about trying to interpret the communications. I have attached the Wireshark capture file so if somebody knows Wireshark maybe they can see something. I will however provide a few observations:
On line 13 I show the outlook server that I have in my PS script. Don.t know why it is connecting to office365 on line 18 & 20. I don’t have an O365 account.
The handshaking and encryption info seems about right to me.
Port 587 is the correct port.
Is it possible my emails are piling up in some O365 server?

Woops, forgot to attach file. How do I attach a file?

Please DO NOT attach a Wireshark capture file!

It might be possible that MSFT changed some conditions. Maybe MFA is mandatory now unless you purposly deactivate it. Sometimes they do something like this to improve security.

I agree with Olaf. There was a change made that broke the process, and likely by M$. What could it hurt to give it a shot?

OK I will give it a shot.