Sending Email using X++ Code (AX2012/D365)

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”);

        }

    }

}

Leave Comment

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