Alfasith AX

Alfasith AX
اللَّهُمَّ انْفَعْنِي بِمَا عَلَّمْتَنِي، وَعَلِّمْنِي مَا يَنْفَعُنِي، وَزِدْنِي عِلْمًا

Wednesday, June 19, 2013

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:\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); 

Regards,

No comments:

Post a Comment

SQL code to upate one Legal entity banner to all the legal entity in D365

 Hi, update companyimage set  companyimage.Image  = companyimageA.Image  from  ( select Image from companyimage where dataAreaid = 'USF...