Fun way to send personalized email to fellow colleagues!

I recently had to write a farewell email to my old colleagues. Most of us do not like to say goodbye, and it can also be somewhat time-consuming, to send a personalized email to every colleague you’ve been in touch with. I made the the below PowerShell script to easily make them more personalized.

Firstly let’s go through how to get the first name out of the Outlook “To” field. Type in the email address you’d like to send emails to and hit CTRL+K to look them up in your address book. 

Copy them over to PowerShell, and you’ll have something that looks like this: Sebastian Schillman <sebastian.schillman@domain.com>; Random Name <random.name@domain.com>

$To = 'Sebastian Schillman <sebastian.schillman@domain.com>; Random Name <random.name@domain.com>'
$Users = ($To -split '; ')
$Cred = Get-Credential # if MFA use a APP Password.

foreach ($User in $Users) {

$FirstName = $User.Substring(0,(($User).IndexOf(' ')))
$EmailAddress = $User.Substring((($User).IndexOf('<')+1)) -replace '>'

$Body = @"
<h4>Hello $FirstName</h4>
     HTML EMAIL BODY
"@

Send-MailMessage -From "UserPrincipalName" -To $EmailAddress -SmtpServer smtp.office365.com -Port 587 -UseSsl -Credential $Cred -BodyAsHtml -Body $Body -Subject "Farewell $FirstName"
}

You do not need any special access to perform above, you only need a Office 365 Account (Can be done with any other email service provider, you just need a SMTP Server)…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.