Pages

Tuesday, 9 September 2014

Sending An Email With Error Exception

          In Order to Sending an Email in Dynamics Ax 2009.First we have to configure the Email Template in Basic---->Setup---->Email Template.
Email Template Form Will be Open.So here Give a Sender Email address and description in that form and creating a new template for your message.........
In Dynamics Ax having a class SmmOutLookEmail for sending email through OutLook..


Example:

static void sendEmailNormal(Args _args)
{
    Description             recipientEmail;
    Notes                   emailBody;
    Description             subjectText;
    Filename                fileName;
    SmmOutlookEmail         smmOutlookEmail = new SmmOutlookEmail();
    Log     log;
    int i=1;
    container con;
    SysInfologEnumerator enum ;
    ;
    recipientEmail = "YourRecipientEmailAddress";
    subjectText     = "Test Email";
    info( "CustTable ");
    error('Syntax Error');
    error('UnReachable codes');
    log = Info::infoCon2Str( infolog.copy(1,infolog.num()));
    con = infolog.copy(1,infolog.num());
    enum = SysInfologEnumerator::newData(con );
    emailBody       = "Hi,\nThis is a test email.\nThanks.\n";
    while (enum.moveNext())
    {
        emailBody +=strfmt('%1 -> %2 ',int2str(enum.currentException()), enum.currentMessage());
    }


    if (smmOutlookEmail.createMailItem())
    {
        smmOutlookEmail.addEMailRecipient(recipientEmail);
        smmOutlookEmail.addSubject(subjectText);
     // smmOutlookEmail.addFileAsAttachment(fileName);
        smmOutlookEmail.addBodyText(emailBody);
        smmOutlookEmail.sendEMail(smmSaveCopyOfEMail::No);
    }
    else
    {
        error("Could not communicate with Microsoft Outlook Client.");
    }

}


  

No comments:

Post a Comment