How to write a Formatted Email using Powershell / Automation

How to write a Formatted Email using Powershell / Automation


Hi Cerebros,

This script will help you to write a formatted email using Powershell :)

With the help of this script, you can send mail with customize date.

You can also have a formatted custom body, html, table, cells and all.

You can automate or schedule this to run occasionally.

When you are sending static mails every time across number of users, you can simply use this script to do your job.

Let the script do its job and you sit back and relax :enjoy your day :)

ThisScript :

# Hi, This script will help you to format mail
# You can use this to automate/schedule mail
# You can also convert this ps1 to exe and schedule it
# I hope it helps :)

#If you want to sent attachment in mail pls mention filename path below
$dir = "c:\crazycerebro\yourfilename.here"


#If you to add dynamic date so that whenever you schedule it should take that particular date
$titleDate = get-date -uformat "%m-%d-%Y - %A"

#here goes our code :)



$smtpsettings = @{

BodyAsHtml = $true

To =  "sender@email.id"

cc = "ifyouwantocopy@anyone.id" 

From = "mailveliveryfrom@id"

Subject = "Your subject here $titledate"

SmtpServer = "Your smtp server name here"

Body = " 

Hi Team,<br>

 <br></br>

This is first line of the body.</br>

<br></br>

<br>This is second line of the body.</br>

<br></br>

<br><b>This is third line of the body.</b></br>



<br></br><br></br>

<style>

table, th, td, tr {

    border: 1px solid black;

    border-collapse: collapse;

}

th, td, tr {

    padding: 5px;

    text-align: left;

}

</style>

<table>

  <caption><b>Table Heading</b></caption>

  <tr>

    <th bgcolor='#CDD1F9'>Column Name1</th>

    <th bgcolor='#CDD1F9'>Column Name2</th>

  <th  bgcolor='#CDD1F9'>  Column Name3 </th>

  </tr>

  <tr>

    <td>Col Value1</td>

    <td>Col value2</td>

    <td>Col Value3</td>

  </tr>

</table>

<br></br><br></br><br></br>

<br> <b> This is  Auto generated mail follow - crazycerebro.blogspot.com</b></br>"



   Attachments = $dir

}

 Send-MailMessage @smtpsettings 

#Here you are done :)

  #Thanks Everyone, i hope you like this script

  #Please comment in the blog if you have any query

 #If you want to make a custom script for you please comment down below I will try my best :)

  Thanks Guys, Comment down below if you have any query :)
Previous
Next Post »
0 Comments