我使用Outlook 2010和Powershell 2.0。使用Powershell發送延期郵件傳遞並更改默認帳戶
我想發送Outlook消息,並使用Powershell以編程方式延遲郵件的發送。
如何創建新的Outlook電子郵件並立即推遲交付?
我使用Outlook 2010和Powershell 2.0。使用Powershell發送延期郵件傳遞並更改默認帳戶
我想發送Outlook消息,並使用Powershell以編程方式延遲郵件的發送。
如何創建新的Outlook電子郵件並立即推遲交付?
如果你試試這個:
$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
解決方案:
$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()
參考文獻:
Create Outlook email draft using PowerShell
更新
要更改默認帳戶:
$Mail.SendUsingAccount = $ol.Session.Accounts | where {$_.DisplayName -eq $FromMail}
參考文獻:
http://msmvps.com/blogs/richardsiddaway/archive/2011/08/08/outlook-sending-emails.aspx
Outlook automation - Change Sender Account
任何想法如何添加CC收件人?有沒有你引用的API? – Brian 2013-02-21 14:33:42
可能是$ Mail對象中的屬性。 – Kiquenet 2013-02-21 14:38:44