1

I use Outlook 2010 and Powershell 2.0.

I want send a Outlook message, and delay delivery programmatically of a message using Powershell.

How can I create a new Outlook email and immediately defer delivery?

2
  • Any idea how you would add CC recipients? Is there an API that you referenced? Commented Feb 21, 2013 at 14:33
  • Maybe properties in $Mail object. Commented Feb 21, 2013 at 14:38

2 Answers 2

3

If you try this:

$ol = New-Object -comObject Outlook.Application  
$mail = $ol.CreateItem(0)  
$mail | Get-Member

you'll get a list of all methods/properties available on the mail object.

One property is DeferredDeliveryTime. You can set it like this:

#Stay in the outbox until this date and time
$mail.DeferredDeliveryTime = "11/2/2013 10:50:00 AM"

Or:

#Wait 10 minutes before sending mail
$date = Get-Date
$date = $date.AddMinutes(10)
$mail.DeferredDeliveryTime = $date
Sign up to request clarification or add additional context in comments.

Comments

0

Solution:

$ol = New-Object -comObject Outlook.Application 
$ns = $ol.GetNameSpace("MAPI")

# call the save method yo dave the email in the drafts folder
$mail = $ol.CreateItem(0)
$null = $Mail.Recipients.Add("[email protected]")  
$Mail.Subject = "PS1 Script TestMail"  
$Mail.Body = "  Test Mail  "

$date = Get-Date
$date = $date.AddMinutes(2)
$Mail.DeferredDeliveryTime = $date #"2/11/2013 10:50:00 AM"

$Mail.save()

# get it back from drafts and update the body
$drafts = $ns.GetDefaultFolder($olFolderDrafts)
$draft = $drafts.Items | where {$_.subject -eq 'PS1 Script TestMail'}
$draft.body += "`n foo bar"
$draft.save()

$inspector = $draft.GetInspector  
$inspector.Display()


# send the message
$draft.Send()

References:

Create Outlook email draft using PowerShell

http://office.microsoft.com/en-us/outlook-help/delay-or-schedule-sending-email-messages-HP010355051.aspx

Update

To change default account:

$Mail.SendUsingAccount = $ol.Session.Accounts | where {$_.DisplayName -eq $FromMail}

References:
http://msmvps.com/blogs/richardsiddaway/archive/2011/08/08/outlook-sending-emails.aspx
Outlook automation - Change Sender Account

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.