Sending
email in AX is now as easy as 123.There are various ways by which we
can send email in Dynamics AX. The code snippet shared here allows the
user to send email through Microsoft Outlook using X++ code.The code is simple and easy to understand.
Description255 recipientEmail;
Notes emailBody;
Description255 subjectText;
Filename fileName;
SmmOutlookEmail smmOutlookEmail = new SmmOutlookEmail();
recipientEmail = "axuser@hotmail.com";
subjectText = "Test Email";
fileName = @"C:\Users\admin\Desktop\mypic.jpg";
emailBody = "Hi,\nThis is a test email for Dyanmics AX.\nThanks.";
if (smmOutlookEmail.createMailItem())
{
smmOutlookEmail.addEMailRecipient(recipientEmail);
smmOutlookEmail.addSubject(subjectText);
smmOutlookEmail.addFileAsAttachment(fileName);
smmOutlookEmail.addBodyText(emailBody);
smmOutlookEmail.sendEMail(smmSaveCopyOfEMail::No,true);
}
else
{
error("Could not communicate with Microsoft Outlook Client.");
}
So, if you want to send email directly without opening in Outlook, replace
smmOutlookEmail.sendEMail(smmSaveCopyOfEMail::No,true);
with
smmOutlookEmail.sendEMail(smmSaveCopyOfEMail::No,false);
===============================================================================
Hi,
static void AppointmentFrom
Outlook(Args _args)
{
COM sysOutlookCollection;
COM receipiants;
COM collection;
COMVariant comStartDate = new COMVariant();
COMVariant comEndDate = new
COMVariant();
COM c;
#SysOutLookCOMDEF
#define.mapi("MAPI")
#define.outlook("Outlook.Application")
COM sysOutlook;
COM sysOutlookNameSpace;
COM sysOutlookMAPIFolder;
sysOutlook = new COM(#outlook);
sysOutlookNameSpace = sysOutlook.getNamespace(#mapi);
sysOutlookNameSpace.logon();
sysOutlookMAPIFolder = sysOutlookNameSpace.getDefaultFolder(#OlDefaultFolders_olFolderTasks);
collection = sysOutlookMAPIFolder.items();
c = collection.add();
comStartDate.date(today());
comStartDate.time(str2Time( "12:00:00"));
comEndDate.date(today());
comEndDate.time(str2Time( "12:15:00"));
c.subject("This is the subject");
c.body("Body of that msg");
c.save();
if (c)
{
receipiants = c.Recipients();
receipiants.add("mdalfasith@gmail.com");
receipiants.ResolveAll();
c.assign();
//c.display();
c.send();
info("Success msg in AX");
}
else
throw error("@SYS31969");
sysOutlookNameSpace.logoff();
}
Description255 recipientEmail;
Notes emailBody;
Description255 subjectText;
Filename fileName;
SmmOutlookEmail smmOutlookEmail = new SmmOutlookEmail();
recipientEmail = "axuser@hotmail.com";
subjectText = "Test Email";
fileName = @"C:\Users\admin\Desktop\mypic.jpg";
emailBody = "Hi,\nThis is a test email for Dyanmics AX.\nThanks.";
if (smmOutlookEmail.createMailItem())
{
smmOutlookEmail.addEMailRecipient(recipientEmail);
smmOutlookEmail.addSubject(subjectText);
smmOutlookEmail.addFileAsAttachment(fileName);
smmOutlookEmail.addBodyText(emailBody);
smmOutlookEmail.sendEMail(smmSaveCopyOfEMail::No,true);
}
else
{
error("Could not communicate with Microsoft Outlook Client.");
}
So, if you want to send email directly without opening in Outlook, replace
smmOutlookEmail.sendEMail(smmSaveCopyOfEMail::No,true);
with
smmOutlookEmail.sendEMail(smmSaveCopyOfEMail::No,false);
===============================================================================
Send task msg from current outlook in Dynamic AX
Hi,
static void AppointmentFrom
Outlook(Args _args)
{
COM sysOutlookCollection;
COM receipiants;
COM collection;
COMVariant comStartDate = new COMVariant();
COMVariant comEndDate = new
COMVariant();
COM c;
#SysOutLookCOMDEF
#define.mapi("MAPI")
#define.outlook("Outlook.Application")
COM sysOutlook;
COM sysOutlookNameSpace;
COM sysOutlookMAPIFolder;
sysOutlook = new COM(#outlook);
sysOutlookNameSpace = sysOutlook.getNamespace(#mapi);
sysOutlookNameSpace.logon();
sysOutlookMAPIFolder = sysOutlookNameSpace.getDefaultFolder(#OlDefaultFolders_olFolderTasks);
collection = sysOutlookMAPIFolder.items();
c = collection.add();
comStartDate.date(today());
comStartDate.time(str2Time( "12:00:00"));
comEndDate.date(today());
comEndDate.time(str2Time( "12:15:00"));
c.subject("This is the subject");
c.body("Body of that msg");
c.save();
if (c)
{
receipiants = c.Recipients();
receipiants.add("mdalfasith@gmail.com");
receipiants.ResolveAll();
c.assign();
//c.display();
c.send();
info("Success msg in AX");
}
else
throw error("@SYS31969");
sysOutlookNameSpace.logoff();
}
No comments:
Post a Comment