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)

24 Comments

  1. Hi, i feel that i saw you visited my website so i came to “go back the choose”.I am trying to to find things to improve my website!I suppose its good enough to use some of your ideas!!

  2. I’m now not positive the place you are getting your information, however great topic. I must spend a while studying more or working out more. Thank you for magnificent info I was searching for this info for my mission.

  3. Hi! This is kind of off topic but I need some advice from an established blog. Is it very hard to set up your own blog? I’m not very techincal but I can figure things out pretty quick. I’m thinking about creating my own but I’m not sure where to begin. Do you have any ideas or suggestions? Cheers

  4. Hello very cool web site!! Man .. Beautiful .. Wonderful .. I’ll bookmark your blog and take the feeds also?KI’m happy to find so many useful info here in the publish, we want work out more strategies in this regard, thank you for sharing. . . . . .

Leave a Reply

Your email address will not be published.