1

我使用 Outlook 2010 和 Powershell 2.0。

我想发送一条 Outlook 消息,并使用 Powershell 以编程方式延迟传递消息。

如何创建新的 Outlook 电子邮件并立即推迟发送?

4

2 回答 2

3

如果你试试这个:

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

您将获得邮件对象上所有可用方法/属性的列表。

一个属性是 DeferredDeliveryTime。你可以这样设置:

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

或者:

#Wait 10 minutes before sending mail
$date = Get-Date
$date = $date.AddMinutes(10)
$mail.DeferredDeliveryTime = $date
于 2013-02-11T09:39:00.987 回答
0

解决方案:

$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("xxxx@serverdomain.es")  
$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()

参考:

使用 PowerShell 创建 Outlook 电子邮件草稿

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

更新

要更改默认帐户:

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

参考: http:
//msmvps.com/blogs/richardsiddaway/archive/2011/08/08/outlook-sending-emails.aspx
Outlook 自动化 - 更改发件人帐户

于 2015-06-18T13:07:38.283 回答