Schedule a recurring email with Outlook and PowerShell

Recurring Email buttonDo you need to send the same emails on a recurring basis like daily, weekly or monthly? Sending out reminders, forwarding reports or the latest offers and prices can be a tedious task.

Outlook doesn’t natively have this feature but with some PowerShell code or add-in, it can be done quite easily .

The PowerShell code in this guide allows you to send an email template, that you’ve created in Outlook. Optionally, it can look for a specific file to attach at the moment of sending to make sure you are always sending the latest version of the file. This guide contains step-by-step instructions to fully automate this process via the Windows Task Scheduler.

Scripts aren’t your thing? We’ve got you covered with some recommended 3rd party add-ins that can bring this functionality to Outlook as well.


Send-OutlookMailFromTemplate PowerShell Script

PowerShell Script buttonThe Send-OutlookMailFromTemplate PowerShell script allows you to send a message template created in Outlook (oft-file). This will give you the full message composing and formatting capabilities of Outlook and the ability to easily edit it if needed.

Optionally, the script allows you to add an attachment at the time of sending to make sure that the file you want to add is always up-to-date without the need to modify the Outlook template.

The script can easily be scheduled in Windows Task Scheduler and can be configured with a recurrence pattern.

Tip!
Don’t like to mess with scripts and PowerShell? There are also ready-made add-ins available to send emails on a (recurring) schedule.

Preparations: Creating the message template (oft-file)

My Template.oft buttonCreate a new message in Outlook and save it somewhere on your disk as an oft-file.

  1. Create a new message and specify at least;
    • To
    • Subject
    • Message body
  2. File-> Save As
  3. Save as type: Outlook Template (*.oft).
  4. Select a convenient folder to save it in.
  5. Specify a file name.
  6. Save.

Save as oft template.

Some things to consider and other tips;

  • Fill out the To address and make sure the address is being resolved (underlined). You can also force this by pressing the Check Names command on the Ribbon, pressing CTRL+K or by selecting the contact from the Address Book.
  • Fill out the subject; Nobody likes emails without subjects.
  • Optionally; Add an attachment. If this should be a file which gets updated just before you sent the message, don’t include the attachment as the script has the option to add it as well. If it is a static attachment (like a general terms and conditions documents), it is best to add it to your template.
  • Create the message body. You can use formatting and pictures as well.

How to use Send-OutlookMailFromTemplate

How? buttonOnce you’ve created your oft-template, you can use the Send-OutlookMailFromTemplate PowerShell script to send it.

  1. Download this code-file (sendoutlookmailfromtemplate.zip) or copy the code below.
  2. Extract the zip-file and copy the Send-OutlookMailFromTemplate.ps1 file to your script repository. If you don’t have one yet, I could recommend creating it in one of the following locations;
    • C:\Scripts
    • \Documents\WindowsPowerShell
  3. As you’ve downloaded the script from the Internet, make sure that it isn’t being blocked by Windows;
    • Right-click the script and choose Properties. In the Properties dialog, if available, select the Unblock checkbox and press OK.
  4. Verify that your PowerShell Execution Policy is set to at least RemoteSigned.
    1. Get-ExecutionPolicy –Scope CurrentUser
    2. Set-ExecutionPolicy –Scope CurrentUser –ExecutionPolicy RemoteSigned
  5. Open PowerShell and execute the OutlookMailFromTemplate.ps1 script. You can use the following script specific parameters;
    1. -Path (mandatory)
      The path to the oft-file. If the path contains spaces, make sure you place it between quotes.
    2. -Attachment (optional)
      The path to a file that you wish to add as an attachment. If the path contains spaces, make sure you place it between quotes.

Tip!
For more info about using PowerShell scripts see; Executing PowerShell Scripts FAQ and Tips & Tricks.

Creating the Recurring Task in Task Scheduler

Task Scheduler buttonTo automate running the script on a specific date or recurrence interval, you can use Task Scheduler.

  1. Open Task Scheduler.
    Just type “Task Scheduler” directly after opening the Start Menu or within the Search box
  2. From the Actions pane on the right choose: Create Basic Task…
  3. Specify a name for the Scheduled Task and press Next.
  4. Select the trigger for the task to run. In this case; Daily, Weekly or Monthly.
  5. Configure the recurrence pattern. 
  6. For the action select: Start a program.
  7. Fill out the Start a program form in the following way;
    • Program/script: PowerShell
    • Add arguments (optional): Path to your PowerShell script including any command line switches (see below for examples).
    • Start in (optional): <leave blank>
  8. Click Next to get an overview of your newly created Task and then click Finish to actually create it.

Example entries for step 7

There are multiple ways to go for specifying the “Add arguments (optional)” line when creating the Task in Task Scheduler.

As we are using a script (ps1-file) with a function in it which accepts command line parameters, we’ll need to use the “-command” command line switch and add a code block as a string;

  • -command "& { . C:\Scripts\Send-OutlookMailFromTemplate.ps1;  Send-OutlookMailFromTemplate -Path 'D:\Templates\My Template.oft' }"
  • -command "& { . C:\Scripts\Send-OutlookMailFromTemplate.ps1;  Send-OutlookMailFromTemplate -Path 'D:\Templates\My Template.oft' -Attachment 'D:\Files\My File.pdf' }"
  • -command "& { . C:\Users\Robert\Documents\WindowsPowerShell\Send-OutlookMailFromTemplate.ps1;  Send-OutlookMailFromTemplate -Path 'D:\Templates\My Template.oft' }"

When you have already dot-sourced the Send-OutlookMailFromTemplate.ps1 in your PowerShell Profile, then you can omit the location of the ps1-file and shorten it to;

  • -command "& { Send-OutlookMailFromTemplate -Path 'D:\Templates\My Template.oft' }"
  • -command "& { Send-OutlookMailFromTemplate -Path 'D:\Templates\My Template.oft' -Attachment 'D:\Files\My File.pdf' }"

Task Scheduler - Create Basic Task Wizard - PowerShell - Command Code Block
Specifying the Task to run PowerShell with a code block.

PowerShell Code

The following code is contained in the zip-file referenced in the how to use section. You can use the code below for review or manual script creation.

function Send-OutlookMailFromTemplate
{
    <#
        .SYNOPSIS
        Sends an email from an Outlook Template (oft-file).

        .DESCRIPTION
        Sends an email from an Outlook Template (oft-file) which you composed earlier.
        Optionally, you can specify an Attachment to be added to the email message when sending.
	This allows you to reuse your template but send it with an up-to-date attachment.

        .PARAMETER Path
        Specifies the path to the oft-file.

        .PARAMETER Attachment
        Optional: Specifies the path to the Attachment.

        .EXAMPLE
        PS C:\> Send-OutlookMailFromTemplate -Path "D:\Templates\My Template.oft"

	.NOTES
	Author: Robert Sparnaaij
	Version: 1.0

        .LINK
        Online version: https://www.howto-outlook.com/howto/schedule-recurring-email.htm

    #>

	[CmdletBinding(DefaultParameterSetName='Send')]
	Param
	(
		[Parameter(Mandatory=$true, Position=0, ParameterSetName='Send')]
		[string] $Path,
		[Parameter(Mandatory=$false, Position=1, ParameterSetName='Send')]
		[string] $Attachment
	)

	If (Get-Process Outlook -ErrorAction SilentlyContinue)
	{$OutlookAlreadyRunning = $true} Else {$OutlookAlreadyRunning = $false}

	$olApp = New-Object -ComObject Outlook.Application
	$objMsg = $olApp.CreateItemFromTemplate($Path)

	If ($Attachment) {
		If (Test-Path $Attachment) {
			$objAttachment = $objMsg.Attachments
			$objAttachment.Add($Attachment) | Out-Null
			[System.Runtime.Interopservices.Marshal]::ReleaseComObject($objAttachment) | Out-Null
		}
	}
	$objMsg.Send()
	[System.Runtime.Interopservices.Marshal]::ReleaseComObject($objMsg) | Out-Null

	If ($OutlookAlreadyRunning -eq $false) {
		$olApp.Quit()
		[System.Runtime.Interopservices.Marshal]::ReleaseComObject($olApp) | Out-Null
		Remove-Variable olApp
	}
}

Schedule a recurring email with 3rd party tools

Add-Ins buttonThere are quite a few 3rd party add-ins available which have even more built in options for scheduling a recurring e-mail with or without attachments. Below are 2 popular tools often used for this with some of their features highlighted;

Schedule Recurring Email by Sperry Software

  • Send the message at hourly, daily, weekly, monthly or yearly intervals.
  • Schedule emails to go out on the first (or last) day/weekday/weekend day of the month.
  • Allows attaching files or even entire folders.
  • Continue to send the messages until a certain date, ‘x’ number of times, or have no end date at all.
  • Discount code: BH93RF24

MAPILab Toolbox by MAPILab

This add-ins contains 3 separate tools to do this:

  • File Send Automatically
    • Automatically send a file after has been changed.
    • Specify a delay before the file is actually sent (to correct mistakes).
    • Rename/relocate/delete the files after sending them
  • E-mail Scheduler
    • Send the message at daily, weekly, monthly or yearly intervals.
    • Allows attaching files or even entire folders.
  • Task Email Scheduler
    • Similar to the Email Scheduler but shows the scheduled email in your Tasks folder as well.
  • Discount code: 4PM76A8

View: More email scheduling add-ins