Create an excel file and send it through Email in D365 using X++ code
This post is about creating an excel file using X++ and attach it as an Email(office 365 SMTP) attachment without saving it in local file location. SysMailerMessageBuilder mailer = new SysMailerMessageBuilder (); SysMailerSMTP smtp = new SysMailerSMTP (); RowNumber row = 1 ; RESPDCLogTable pDCLogTable1; System.IO. MemoryStream memoryStream = new System.IO. MemoryStream (); mailer.setSubject(strFmt( "PDC posted batch status %1" ,sessionDate)); mailer.setFrom( SysUserInfo ::find().Email); mailer.setBody( 'Please find the PDC Status report.' ); mailer.addTo(' ToMailAddress ' ); using ( var package = new OfficeOpenXml. ExcelPackage (memoryStream)) { var worksheets = package.get_Workbook().get_Worksheets(); var worksheet = worksheets.Add( "PDC batch status" ); var cells = worksheet.get_Cells(); var cell = cel