X++ code to send simple email from D365 FO
Views (318)
Hi,
In this post we will view to send simple email using X code from D365FO. This code can be used to test the email functionality.
Note: This post doesn't contain the settings & configuration for email setup which will be explained in another post.
X code:
class DAX_SendSimpleEmail { ////// Runs the class with the specified arguments. /// /// The specified arguments. public static void main(Args _args) { SysMailerMessageBuilder messageBuilder = new SysMailerMessageBuilder(); Email fromEmail = "sender@domain.com"; Email toEmail = "recipient@domain.com"; str subject = "Sample email"; str body = "Email body"; try { // Sender email messageBuilder.setFrom(fromEmail); // Subject messageBuilder.setSubject(subject); // Body messageBuilder.setBody(body, false); // Recipient email messageBuilder.addTo(toEmail); SysMailerFactory::sendInteractive(messageBuilder.getMessage()); } catch (Exception::Error) { throw error("@ApplicationFoundation:EmailProviderNotFound"); } } }
Output:
On executing the above code, we receive the below output. We have to choose the first option, click on Ok button to proceed further.
Regards,
Chaitanya Golla
*This post is locked for comments