Table of Contents

Introduction

You can automate or schedule this to run occasionally.

You are sending static mails everytime across number of users, you can simple use this script to do your job.

Let the script do its job and you sit back and relax.

Script

# 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:\temp\yourfilename.suffix"

 

 

#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

Download

Download Script - CrazyCerebro