Sending Email using X++ Code (AX7 /D365 for Operations)

Friends,

I was just researching on the emailing capabilities in D365 and found that SysINetMail, SysMailer and some of the smmOutlook classes are deprecated because these classes used predominantly client-side technologies that are no longer available

Below is the quick code snippet that can be used in D365 to send emails. Please note, this is just a untested sample code, with out any setups configured. please ensure all setups are done and improvise the code accordingly.

SysMailerFactory class internally used SysImailer* classes to send emails.

class SRSendEmail_D365

{       

    public static void main(Args _args)

    {  

        SysMailerMessageBuilder messageBuilder = new SysMailerMessageBuilder();

        Email   toEmail;

        Email   fromEmail;

         

        try

        {

            FromEmail = "sreddy@xyzcompany.com";

            toEmail   = "tester@xyzcompany.com";

 

            messageBuilder.setBody("Hello from D365", false);

            messageBuilder.setSubject("Email Test from D365");

            messageBuilder.addTo(toEmail);

            // Note: not calling setFrom() defaults to the current user for SMTP client, whereas

            // when sent to Outlook any setFrom() value will be ignored since profiles on the client are used

            messageBuilder.setFrom(fromEmail);

 

            // Open the generated email in the configured client

            // Sends a message interactively, allowing the user to view and modify the message before

            SysMailerFactory::sendInteractive(messageBuilder.getMessage());

            // Try using sendNonInteractive method too

        }

        catch (Exception::Error)

        {

            throw error("@SYS33567");

        }

    }

 

}

Happy Dax6ng,

image

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: