使用PowerShell的创建Outlook电子邮件草稿 [英] Create Outlook email draft using PowerShell

查看:1485
本文介绍了使用PowerShell的创建Outlook电子邮件草稿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个PowerShell脚本在工作自动化的过程。这个过程需要填写并发送到他人的电子邮件。电子邮件将始终大致遵循同一种模板但它可能永远不会每次都一样的,所以我要在Outlook中创建一个电子邮件草稿,并打开电子邮件窗口,使多余的细节可以在发送之前进行填充。

我已经做了一些搜索网上的,但所有我能找到一些code默默发送电子邮件。在code是如下:

  $ OL =新对象-ComObject Outlook.Application
$电子邮件= $ ol.CreateItem(0)
$ Mail.Recipients.Add(XXX@YYY.ZZZ)
$ Mail.Subject =PS1脚本TestMail
$ Mail.Body =
测试邮件

$ Mail.Send()

总之,没有任何人有任何想法如何创建和保存新的Outlook电子邮件草稿,并立即打开该草案修改?


解决方案

  $ olFolderDrafts = 16
$ OL =新对象-ComObject Outlook.Application
$ NS = $ ol.GetNameSpace(MAPI)#调用保存方法哟戴夫的电子邮件草稿文件夹
$电子邮件= $ ol.CreateItem(0)
$空= $ Mail.Recipients.Add(XXX@YYY.ZZZ)
$ Mail.Subject =PS1脚本TestMail
$ Mail.Body =测试邮件
$ Mail.save()#从草稿拿回来,并更新体
$汇票= $ ns.GetDefaultFolder($ olFolderDrafts)
$草案= $ drafts.Items |其中{$ _。受-eqPS1脚本TestMail'}
$ draft.body + =`ñ富巴
$ draft.save()#发送邮件
#$ draft.Send()

I'm creating a PowerShell script to automate a process at work. This process requires an email to be filled in and sent to someone else. The email will always roughly follow the same sort of template however it will probably never be the same every time so I want to create an email draft in Outlook and open the email window so the extra details can be filled in before sending.

I've done a bit of searching online but all I can find is some code to send email silently. The code is as follows:

$ol = New-Object -comObject Outlook.Application  
$mail = $ol.CreateItem(0)  
$Mail.Recipients.Add("XXX@YYY.ZZZ")  
$Mail.Subject = "PS1 Script TestMail"  
$Mail.Body = "  
Test Mail  
"  
$Mail.Send()

In short, does anyone have any idea how to create and save a new Outlook email draft and immediately open that draft for editing?

解决方案

$olFolderDrafts = 16
$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("XXX@YYY.ZZZ")  
$Mail.Subject = "PS1 Script TestMail"  
$Mail.Body = "  Test Mail  "
$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()

# send the message
#$draft.Send()

这篇关于使用PowerShell的创建Outlook电子邮件草稿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆