- 1 year ago
HTML formatted report – email via PowerShell
To send an HTML-formatted report via PowerShell, you can use the Send-MailMessage
cmdlet along with the appropriate parameters. Here's an example of how to accomplish this:
powershell# Set the email parameters
$smtpServer = "your_smtp_server"
$from = "sender@example.com"
$to = "recipient@example.com"
$subject = "HTML Report"
$htmlBody = Get-Content -Path "path_to_html_file" -Raw
# Create the email message
$emailParams = @{
From = $from
To = $to
Subject = $subject
Body = $htmlBody
BodyAsHtml = $true
SmtpServer = $smtpServer
}
# Send the email
Send-MailMessage @emailParams
Make sure to replace "your_smtp_server"
, "sender@example.com"
, "recipient@example.com"
, and "path_to_html_file"
with your actual values.
In this example, the Get-Content
cmdlet is used to read the contents of an HTML file and store it in the $htmlBody
variable. The Send-MailMessage
cmdlet is then used to send the email with the HTML body.
Ensure that you have a functioning SMTP server available and provide the correct SMTP server address ($smtpServer
) to send the email successfully.
By running this PowerShell script, you will be able to send an HTML-formatted report via email using the Send-MailMessage
cmdlet.