Wednesday, March 9, 2011

How to populate an Outlook Client by Creating a Mail Item, Attach a Report, and Send the Mail through AX 2009

Hi Folks,

In AX, using SysMailer class we can compose a mail and send it through code in AX but if we would like to populate the outlook client by creating a mail item then attaching a report and also attaching the sender's email address as well as subject to it then here is the code snippet for it:

COM sysOutlook;
COM sysOutlookNameSpace;
COM sysOutlookMailItem;
COM sysOutlookAttachment;
COM sysOutlookRecipient;

sysOutlook = new COM(#outlook);
sysOutlookNameSpace = sysOutlook.getNamespace(#mapi);
sysOutlookMailItem = sysOutlook.CreateItem('Outlook.OlItemType.olMailItem');
sysOutlookAttachment = sysOutlookMailItem.Attachments();

info("The action is created in Microsoft Outlook");

So, if you would like to send it and instead of display() method, just use the Send() method in sysOutlookMailItem class above.

1 comment:

Drakon said...

Thanks for the code! ;)