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:

#SysOutLookCOMDEF

#define.outlook(“Outlook.Application”)
#define.mapi(“MAPI”)
COM sysOutlook;
COM sysOutlookNameSpace;
COM sysOutlookMailItem;
COM sysOutlookAttachment;
COM sysOutlookRecipient;
;
sysOutlook = new COM(#outlook);
sysOutlookNameSpace = sysOutlook.getNamespace(#mapi);
sysOutlookNameSpace.logon();
sysOutlookMailItem = sysOutlook.CreateItem(‘Outlook.OlItemType.olMailItem’);
sysOutlookMailItem.To(“test@test.com”);
sysOutlookMailItem.Subject(“Hi-Test”);
sysOutlookAttachment = sysOutlookMailItem.Attachments();
sysOutlookAttachment.Add(@”C:New.pdf”,1,1,”New”);
sysOutlookMailItem.save();
sysOutlookMailItem.display();
info(“The action is created in Microsoft Outlook”);
sysOutlookNameSpace.logoff();


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

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

0 Comments