Quantcast
Channel: Microsoft Technologies Blog » MS Exchange
Viewing all articles
Browse latest Browse all 4

Send HTML Email and attachment Powershell

$
0
0

Hi Readers,

Sharing a sweet code to send HTML email via powershell.

Attached is a very simple method for sending the html email.

zip file contains script & html file (you can edit in MS word according to your requirement).

Most of the parameters that  are required to send email are used, you can use what ever you require.

Extract the zip file & Check the sample.

If you search on Internet you will find complex method in which scripters have used html code inside the script.

I have used a very simple method by creating the word file & saving it as html.

Script also sends attachment, if you want to send attachment then change the path accordingly in variables. (# Hash the things that you don’t require in your script email)

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

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

$fromaddress = "donotreply@labtest.com" 
$toaddress = "Aishwarya.Rawat@labtest.com" 
$bccaddress = "Vikas.sukhija@labtest.com" 
$CCaddress = "Mahesh.Sharma@labtest.com" 
$Subject = "ACtion Required" 
$body = get-content .\content.htm 
$attachment = "C:\sendemail\test.txt" 
$smtpserver = "smtp.labtest.com" 

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

$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) 

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

Script download Location:-

http://gallery.technet.microsoft.com/scriptcenter/Send-HTML-Email-Powershell-6653235c

Regards
SUkhija Vikas


Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images