Sending email through Outlook in Dynamics AX
Views (2322)
Hi,
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);
That's it.
Happy coding!
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);
That's it.
Happy coding!
This was originally posted here.

Like
Report
*This post is locked for comments