Home » Powershell » Send HTML Email and attachment using Powershell

Send HTML Email and attachment using Powershell

 Powershell script to email 

###########Define Variables########

$date = “get-date”
$fromaddress = “[email protected]
$toaddress = “[email protected]
$Subject = “Test $(get-date)”
$body = Get-Content C:\temp\Test.htm
#$attachment = “C:\sendemail\test.txt”
$smtpserver = “SMTP Server name”

####################################

$message = new-object System.Net.Mail.MailMessage
$message.From = $fromaddress
$message.To.Add($toaddress)
#$message.CC.Add($CCaddress)
#$message.Bcc.Add($bccaddress)
$message.IsBodyHtml = $True
$message.Subject = $Subject
#$attach = new-object Net.Mail.Attachment($attachment)
#$message.Attachments.Add($attach)
$message.body = $body
$smtp = new-object Net.Mail.SmtpClient($smtpserver)
$smtp.Send($message)

Leave a Reply

Your email address will not be published. Required fields are marked *

Name *
Email *
Website