FinOps: Send Email in X++ using email templates
Usama Mehmood
Senior Technical Consultant ERP / Microsoft Dynamics 365 Finance & Operations | Integration & Customization specialist | Enabler of Business | Digital Transformation
Sending Email using X++ Code in D365 F&O/ AX 7
In this article, we will learn how we can trigger email from finOps to Outlook or any other medium through code in X++. I was just develped on the emailing capabilities in finops and worked on SysINetMail, SysMailer and some of the smmOutlook classes are deprecated because these classes used predominantly client-side technologies that are no longer available.
As we know in D365FO there are an option available to send in CC. please have look the below. My question is how can we send email in CC & BCC using X++ in D365FO.
The main aim of this document is to demonstrate how we can send emails in X++ using built-in email templates. For demonstration purposes we’ll be using standard email template.
Source Code Representation
?public static void emailImplementation(str id, str recipeName, str BomItemId, str bulkProductId)
??{
????str message = "The Recipe Id?" + id +"contains the recipe name?" + recipeName + " with PW product id?" + BomItemId + "and bulk product id?" + bulkProductId;
????SysMailerMessageBuilder messageBuilder = new SysMailerMessageBuilder();
????Email??toEmail;
????Email??fromEmail;
?????
????try
????{
??????FromEmail = "[email protected]";
??????toEmail??= "[email protected]";
??????messageBuilder.setBody("Hello from finops", false);
??????messageBuilder.setSubject("Email Test from finops");
??????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");
????}
??}
Thank you,
Happy Learning!!!
D365 Finance & Operation Technical Consultant
1 年why are you making fool to people,where you used template?
Senior Developer | D365 Security | D365FO | AX | Azure DevOps
1 年Which template was used here?