Monday, January 23, 2023

Send Email from D365FO

 public void sendMail()
    {
        SysMailerMessageBuilder messageBuilder = new SysMailerMessageBuilder();
        Email   toEmail;
        Email   fromEmail;
         
        try
        {
            FromEmail = "fromemail@xyz.com";
            toEmail   = "toemail@xyz.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::sendNonInteractive(messageBuilder.getMessage());
            // Try using sendNonInteractive method too
        }
        catch (Exception::Error)
        {
            throw error("@SYS33567");
        }
    }

No comments:

Post a Comment

Table browser URL in D365FO

Critical Thinking icon icon by Icons8