preloader-matrix

Alfasith

Sending email through Outlook in Dynamics AX

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 = “mdalfasith@gmail.com”;
    subjectText     = “Test Email”;
    fileName          = @”C:UsersadminDesktopmypic.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);
Regards,

Leave a Reply

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