Send-MailMessage

Glenn Maxwell 12,871 Reputation points
2024-04-30T22:09:49.3733333+00:00

Hi All

I am using exchange 2016 hybrid environment. i am trying to trigger test email from exchange PowerShell using the below syntax but i am unable to. Please guide me with the syntax. 192.168.1.10 is my onprem exchange server.

1..10 | %{Send-MailMessage -from "******@mydomain.com -to "******@mydomain.com" -port 25 -subject Get-Date -Format "yyyy-MM-dd HH:mm:ss.fff" -SmtpServer 192.168.1.10}

Exchange Online
Exchange Online
A Microsoft email and calendaring hosted service.
6,171 questions
Exchange Exchange Server Other
Exchange Exchange Server Management
Exchange Hybrid management
{count} votes

1 answer

Sort by: Most helpful
  1. Andreas Baumgarten 123.4K Reputation points MVP Volunteer Moderator
    2024-04-30T22:27:32.7333333+00:00

    Hi @Glenn Maxwell ,

    what does "I am unable to" mean? Any error messages?

    You can try this please:

    $From = "******@mydomain.com"
    $To = "******@mydomain.com"
    $SMTPServer = "192.168.1.10"
    $Body = "This is a test email."
    for ($i = 1; $i -le 10; $i++) {
        $Subject = (Get-Date).ToString("yyyy-MM-dd HH:mm:ss.fff")
        Send-MailMessage -From $From -To $To -Subject $Subject -Body $Body -SmtpServer $SMTPServer -Port 25
        Write-Output "Email $i sent."
    }
    

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards

    Andreas Baumgarten

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.