→ 🚀What's New? Join Us for the Fall Product Launch! Register Now !
‎01-04-2023 11:27 AM - last edited on ‎04-01-2024 03:42 PM by Mercedes_O
Hi,Just wanted to share as it may be of use to other Lansweeper Users, the following steps will allow you to send preformatted HTML emails to users via Outlook, email includes the email address and User Name plus any content you desire, saving time, especially useful if you just want to drop the User a quick email asking them to reboot, etc
Create a User Action with the following :
powershell.exe -executionpolicy bypass -file {actionpath}email.ps1 {email} {username}
Place the following Powershell script in the Action directory on the Lansweeper server and name it email.ps1
$outlook = New-Object -comObject Outlook.Application
$emailadd=$args[0]
$UserName=$args[1]
$Body = "Dear $UserName,<BR><BR>"
$Body += "A recent audit has identified a pc you use or are assigned to hasn't been rebooted for <U><B> <<>> Days </B></U> and requires a restart to install important Windows Updates.<BR><BR>"
$Body += "Email Text.<BR>"
$Body += "Email Text<BR>"
$Body += "<BR>"
$Body += "Kind Regards"
$mail = $outlook.CreateItem(0)
$mail.To = "$emailadd"
$mail.Subject = "Asset Reboot Required"
$mail.HTMLBody = "$Body"
$mail.save()
$inspector = $mail.GetInspector
$inspector.Display()
You can add additional $Body+="" for each line of the email adding HTML tags for formatting, colours, etc . When you then click the User action Outlook will generate the preformatted email , you should be able to add a FROM address if its not the default account you want to send from?
‎01-10-2023 10:58 AM
Hello there!
Thanks for sharing!
‎01-11-2023 10:54 AM
I have added some improvements , Split the User Name and added uppercase to First and Last Name, I have also include a nicer email format , here is the updated powershell
$outlook = New-Object -comObject Outlook.Application
$emailadd=$args[0]
$UserName=$args[1]
$CleanUN=$UserName.replace('.',' ')
$words=$UserName.split(".")
$UserName=""
foreach ($word in $words){
$givenname+=$word.substring(0,1).toupper()+$word.substring(1)+" "}
$givenname=$givenname.trim()
$Body=@"
<p> </p>
<table style="border: 1px solid #FF6600; width: 650px;" border="0" cellspacing="0" cellpadding="2">
<tbody>
<tr>
<td style="width: 10px;" bgcolor="#FF6600"> </td>
<td style="width: 53.1562px;" align="left" bgcolor="#FF6600"><img src="LOGO" alt="" width="70" height="70" /></td>
<td style="width: 286.844px;" align="left" bgcolor="#FF6600">
<h2 style="color: white; font-family: 'Arial',sans-serif;">Your Team Name</h2>
</td>
<td style="width: 297px;" align="right" bgcolor="#FF6600"><img src="LOGO" alt="" /></td>
</tr>
<tr>
<td style="width: 647px;" colspan="4">
<p><span style="color: #FF6600; font-family: 'Arial',sans-serif; font-size: 16.0pt;">Import Email </span></p>
<p><span style="font-size: 14px; background-color: white; font-family: 'Arial',sans-serif;">Dear $givenname</span></p>
<p><span style="font-size: 14px; background-color: white; font-family: 'Arial',sans-serif;">To dread of soment a contumely, thought his rath the hue of thous calamity opposings a weathe have, an.</span></p>
<p><span style="font-size: 14px; background-color: white; font-family: 'Arial',sans-serif;"></span><span style="color: #FF6600; font-family: 'Arial',sans-serif; font-size: 14.0pt;">To dread of soment a contumely, thought his rath the hue of thous calamity opposings</span></p>
<p><span style="font-size: 14px; background-color: white; font-family: 'Arial',sans-serif;">Thus fortune, the of? Thers thers the native heir currenterprises of? To dread of soment a contumely, thought his rath the hue of thous calamity opposings a weathe have, and thing end sweathem? To be, to say wear, ther 'tis rath, ther 'tis no takes us againsolution. Ther be, and, but the arms all; and lose ills be: to gream: ay, and morthy to sleep of action: whethe name whethe with who would be, that man's devoutrageous pangs and than fly take and their the who would by of some wish'd. Ther resolen.</span></p>
<ul>
<li><span style="font-size: 13px;"><span style="color: #FF6600; font-family: Arial,sans-serif;">end name with the pangs of</span></span></li>
<li><span style="font-size: 13px;"><span style="color: #FF6600; font-family: Arial,sans-serif;">end name with the pangs of</span></span></li>
<li><span style="font-size: 13px;"><span style="color: #FF6600; font-family: Arial,sans-serif;">end name with the pangs of</span></span></li>
<li><span style="font-size: 13px;"><span style="color: #FF6600; font-family: Arial,sans-serif;">end name with the pangs oft &</span></span></li>
<li><span style="font-size: 13px;"><span style="color: #FF6600; font-family: Arial,sans-serif;">end name with the pangs of.</span></span></li>
</ul>
<p><span style="color: #FF6600; font-family: 'Arial',sans-serif; font-size: 14.0pt;">Further Support</span></p>
<p><span style="font-size: 14px; background-color: white; font-family: 'Arial',sans-serif;">cowardels beary from whethings of </span><span style="font-size: 13px;"><span style="color: #FF6600; font-family: Arial,sans-serif;"><a href="mailto:You@You.Comt"><span style="font-family: 'Arial',sans-serif;">You@You.Com</span></a></span></span></p>
<p> </p>
</td>
</tr>
<tr>
<td style="width: 647px;" colspan="4" align="center" bgcolor="#FF6600" height="20">
<p><a style="color: #fffff6; font-family: 'Arial',sans-serif; font-size: 8.0pt;" href="mailto:You@You.comt">Your Team</a></p>
</td>
</tr>
</tbody>
</table>
</tr>
<tr>
<td colspan="4" bgcolor="#FF6600" height="20" align="center"><p><a href="mailto:You@You.comt" style="color:#FFFFF6; font-family:"Arial",sans-serif; font-size:8.0pt">but there's the </a></p></td>
</tr>
</tbody>
</table>
"@
$mail = $outlook.CreateItem(0)
$mail.To = "$emailadd"
$mail.Subject = "Asset Reboot Required"
$mail.HTMLBody = "$Body"
$mail.save()
$inspector = $mail.GetInspector
$inspector.Display()
Experience Lansweeper with your own data. Sign up now for a 14-day free trial.
Try Now