开发者

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. 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:

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. 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. All the "VB" examples on MSDN produce syntax errors when run through the VBScript interpreter.

Can anyone point me to any short examples demonstrating how to interface with Outlook 2010 using either VBScript or JScript?

EDIT: Just realised the problem is that I'm using 开发者_运维百科MAPI.Session to adjust attachment properties and this is what's failing. 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"). 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.

So all I actually had to do was remove the MAPI.Session stuff and then everything started working. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜