Search This Blog

Friday 9 June 2023

Sending Email to Multiple recipients using PowerShell

Hi All, 

Below is the working code to Send emails to Multiple recipients using PowerShell.


[STRING]$PSEmailServer = "YourSMTPServerIPOrName"

[STRING]$Subject = "YourSubject"

[STRING]$From = "From@from.com"

[STRING[]]$EmailTo = "To1@To.com", "To2@To.com"

[STRING]$mailBodyPT = "Your Mail Body Goes Here"

[STRING]$HTMLmessage = @"

<font color=""black"" face=""Arial"" size=""3"">

<h1 style='font-family:arial;'><b>YourHeader</b></h1>

<p style='font: .8em ""Lucida Grande"", Tahoma, Arial, Helvetica, sans-serif;'>$mailTextReportPT</p>

<style type=""text/css"">body{font: .8em ""Lucida Grande"", Tahoma, Arial, Helvetica, sans-serif;}

ol{margin:0;}

table{width:80%;}

thead{}

thead th{font-size:120%;text-align:left;}

th{border-bottom:2px solid rgb(79,129,189);border-top:2px solid rgb(79,129,189);padding-bottom:10px;padding-top:10px;}

tr{padding:10px 10px 10px 10px;border:none;}

#middle{background-color:#900;}

</style>

<body BGCOLOR=""white"">

$mailBodyPT

</body>

"@


Send-MailMessage -From $From -To $EmailTo -Subject $Subject -Body $HTMLmessage -BodyAsHtml -SmtpServer $PSEmailServer

No comments:

Post a Comment

Sending Email to Multiple recipients using PowerShell

Hi All,  Below is the working code to Send emails to Multiple recipients using PowerShell. [STRING]$PSEmailServer = "YourSMTPServerIPOr...