Powershell : email Flow Script

I had an issue with some routing and wanted to check that the mails were being sent, so rather than manually send lots of e-mails I turned to PowerShell to get automated emails to to see if mail flow was indeed did stop, this is the script, you need to customise the lines in bold.

Note: I used an internal relay server for this test as I had one to use, you can also use an Exchange connector but for that I would recommend using SSL and TCP:587

# Define the function to send the email
function Send-TestEmail {
    $EmailParams = @{
        From = "<from_address>"
        To = "<target_Address>"
        Subject = "Test Email - $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')"
        Body = "This is a test email flow."
        SmtpServer = "<internal-smtp_Server>"
        Port = 25
    }

Send-MailMessage @EmailParams
}

# Define the interval in minutes (10 minutes)
$IntervalMinutes = 10

# Start an infinite loop

while ($true) {

# Call the function to send the email

    Send-TestEmail

# Sleep for the specified interval

    Start-Sleep -Seconds ($IntervalMinutes * 60)
}

This is what this will look like when its running, you get an e-mail with the date and time every 10 minutes........


If we look at this in more detail you will notice there is a gap between the 19th March 2024 at 21:27 and 20th March 2024 at 06:58 - during this time no email was delivered externally as you can see here:


However Exchange message tracking says they were delivered successfully though the night as you can see below:


This means the "mail platform provider" we were testing with was not sending the message back to our Exchange to then send the message on to the intended recipient, but why could this be, well as we use a "mail platform provider" I though I would check the response from their IP on the blacklist, and what do you know they seem to be on the CSS blacklist with SpamHaus as below:


That now explains why I am not getting the messages externally, they are not being send as the server sending them is on a blacklist, which is now, due to it being the CSS list, its now publically visible from any Blacklist checker:



Exchange uses SpamHaus as a source of blacklisted IP addresses, so when the additional rules were disabled mail started flowing once again, but this is down the "mail platform provider" to investigate this issue in the meantime this rule remains disabled.


Previous Post Next Post

Ω†Ω…ΩˆΨ°Ψ¬ Ψ§Ω„Ψ§ΨͺΨ΅Ψ§Ω„