简体   繁体   English

Outlook 2010:如何从 VBScript/JScript 撰写电子邮件

[英]Outlook 2010: How to compose e-mail from VBScript/JScript

I have some JScript code I have been using for a few years which is able to read an XML file and open an Outlook compose window with the to/cc/subject fields prepopulated and files pre-attached based on the XML data.我有一些 JScript 代码,我已经使用了几年,它能够读取 XML 文件并打开 Outlook 撰写窗口,其中预填充了 to/cc/subject 字段,并根据 XML 数据预先附加了文件。 The user can then attach more files, make any corrections and send the e-mail.然后,用户可以附加更多文件、进行更正并发送电子邮件。 The core part of the code uses CDO to create the new message:代码的核心部分使用 CDO 创建新消息:

var ol = WScript.CreateObject("Outlook.Application");
var msg = ol.CreateItem(olMailItem);

Unfortunately I have just discovered this no longer works with Outlook 2010 64-bit as CDO is no longer supported.不幸的是,我刚刚发现这不再适用于 Outlook 2010 64 位,因为不再支持 CDO。 The suggestion from Microsoft is to update your applications to use the Outlook object model instead, but I can't find any examples at all of how I might use the Outlook object model to open a compose window from either VBScript or JScript. Microsoft建议是更新您的应用程序以改用 Outlook 对象模型,但我根本找不到有关如何使用 Outlook 对象模型从 VBScript 或 JScript 打开撰写窗口的任何示例。 All the "VB" examples on MSDN produce syntax errors when run through the VBScript interpreter. MSDN 上的所有“VB”示例在通过 VBScript 解释器运行时都会产生语法错误。

Can anyone point me to any short examples demonstrating how to interface with Outlook 2010 using either VBScript or JScript?任何人都可以向我指出任何简短的示例来演示如何使用 VBScript 或 JScript 与 Outlook 2010 交互?

EDIT: Just realised the problem is that I'm using MAPI.Session to adjust attachment properties and this is what's failing.编辑:刚刚意识到问题是我正在使用 MAPI.Session 来调整附件属性,这就是失败的原因。 I guess I need to find what this has been replaced by:我想我需要找到这已被替换的内容:

var oSession = WScript.CreateObject("MAPI.Session");
oSession.Logon("", "", false, false);
var oMsg = oSession.GetMessage(strMsgID);
var oAttachFields = oMsg.Attachments.Item(i+1).Fields;
...

Ok, turns out most of the MAPI.Session stuff has been merged in with the actual objects, which are still accessible using the first bit of code in my post ("Outlook.Application").好的,事实证明大部分 MAPI.Session 内容已与实际对象合并,这些对象仍然可以使用我帖子中的第一部分代码(“Outlook.Application”)访问。 I was only using the MAPI.Session stuff to hide image attachments (so they can be shown inline in the message body, and not as files attached to the e-mail) but this now seems to be incorporated automatically.我只是使用 MAPI.Session 来隐藏图像附件(因此它们可以在消息正文中内嵌显示,而不是作为附加到电子邮件的文件),但现在这似乎是自动合并的。

So all I actually had to do was remove the MAPI.Session stuff and then everything started working.所以我实际上所要做的就是删除 MAPI.Session 的东西,然后一切都开始工作了。 I will post a link to the code shortly in case anyone else finds it useful.我将很快发布代码的链接,以防其他人发现它有用。

EDIT: Here is the code on GitHub if anyone is after a relatively simple example.编辑:如果有人想要一个相对简单的例子,这里是 GitHub 上的代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM