Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Email 使用Powershell发送延迟邮件传递并更改默认帐户_Email_Powershell_Outlook - Fatal编程技术网

Email 使用Powershell发送延迟邮件传递并更改默认帐户

Email 使用Powershell发送延迟邮件传递并更改默认帐户,email,powershell,outlook,Email,Powershell,Outlook,我使用Outlook 2010和Powershell 2.0 我希望发送Outlook邮件,并使用Powershell以编程方式延迟邮件的传递 如何创建新的Outlook电子邮件并立即延迟发送?如果您尝试以下方法: $ol = New-Object -comObject Outlook.Application $mail = $ol.CreateItem(0) $mail | Get-Member 您将获得mail对象上所有可用方法/属性的列表 一个属性是DelferredDelive

我使用Outlook 2010和Powershell 2.0

我希望发送Outlook邮件,并使用Powershell以编程方式延迟邮件的传递

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

如果您尝试以下方法:

$ol = New-Object -comObject Outlook.Application  
$mail = $ol.CreateItem(0)  
$mail | Get-Member
您将获得mail对象上所有可用方法/属性的列表

一个属性是DelferredDeliveryTime。您可以这样设置:

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


解决方案:

$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()
参考资料:

更新

要更改默认帐户,请执行以下操作:

$Mail.SendUsingAccount = $ol.Session.Accounts | where {$_.DisplayName -eq $FromMail}
参考文献:


知道如何添加抄送收件人吗?是否有您引用的API?可能是$Mail对象中的属性。
$Mail.SendUsingAccount = $ol.Session.Accounts | where {$_.DisplayName -eq $FromMail}