Blog

Name is Anant Dubey and the intent to create this blog is to discuss the problems and issues that developer face in the dynamics AX development and to share the new things that come up with the new version of AX.

Sunday, February 16, 2020

How to send email using email template by Outlook in AX 2012

static void AD_SendEmailOutlook(Args _args)
{
    SysEmailId           emailId;
    DialogField          dlgEmailId;
    CustTable            custTable;
    LanguageId           languageId = 'EN-IN';
    #define.CurrentVersion(1)
    #localmacro.CurrentList
        emailId
    #endmacro
    SendEmail           sendEmail;
    SysInetMail         mail;
    str subject()
    {
        return SysEmailMessageTable::find(emailId, languageId).Subject;
    }
    str processMappings(str _message)
    {
        Map mappings;
        ;
        mappings = new Map(Types::String, Types::String);
        mappings.insert('CustomerName', "Anu");
        mappings.insert('CustomerStreet', "Testingg");
        return SysEmailMessage::stringExpand(_message, mappings);
    }
    str message()
    {
        COM                  document;
        COM                  body;
        str                  ret;
        SysEmailMessageTable message;
        #help
        ;
        message = SysEmailMessageTable::find(emailId, languageId);
        ret = processMappings(message.Mail);
        //ret = WebLet::weblets2Html4Help(ret, '');
        document = new COM(#HTMLDocumentClassName);
        SysEmailTable::insertHTML2Document(document, ret);
        body = document.body();
        if (!body)
        {
            return '';
        }
        return body.outerText();
    }

    ;
    //sendEmail = new SendEmail();
    emailId = "Test";
    mail = new SysInetMail();
    mail.parmForceSendDialog(true);
    mail.sendMail("support@****.com",subject(), message(),false);
    info("sent");
}

No comments:

Post a Comment