web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

How to create an Excel file and send it by Email, using code x++

(0) ShareShare
ReportReport
Posted on by

I need to create an Excel file and to send it by Email, by X++ code in to Dyncamics AX2012. If it's possible I don't want to save the data in a physical path/folder.

I wrote this code, but after I need to send the Excel.

I would like to follow the D365 instructions (https://axexplorer.wordpress.com/2017/07/18/create-an-excel-file-and-send-it-through-e-mail-in-d365-for-operationax-7/ )in Dynamics AX 2012 (In AX2012 some command are not available)

SysEmailParameters parameters = SysEmailParameters::find();
SMTPRelayServerName relayServer;
SMTPPortNumber portNumber;
SMTPUserName userName;
SMTPPassword password;
Str1260 subject,body;
InteropPermission interopPermission;
SysMailerMessageBuilder  mailer;
SysMailerAttachments attach;
System.Exception e;

SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
SysExcelCell cell;

int row;
str contact;
int recordscount;
MYTABLE myTable;
System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();
row = 1 ;

mailer.subject("MY subject");
mailer.fromAddress("MY_from@com");
mailer.htmlBody("MY_BODY");
mailer.tos().appendAddress("MY_to.com");

application = SysExcelApplication::construct();

workbooks = application.workbooks();
workbook = workbooks.add();
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();
//cells.range(‘A:A’).numberFormat(‘@’);
cell = cells.item(1,1);
cell.value("Field_I");
cell = cells.item(1,2);
cell.value("Field_II");

while select myTable
{
    row++;

    cell = cells.item(row, 1);
    cell.value(myTable.Field_I);
    cell = cells.item(row, 2);
    cell.value(myTable.Field_I);
}
application.visible(true);
application.save();
memoryStream.Seek(0, System.IO.SeekOrigin::Begin);

I'm not able to save the file in temporary stream.

In AX2012 are not available the

SysMailerMessageBuilder mailer = new SysMailerMessageBuilder();;
var package = new OfficeOpenXml.ExcelPackage(memoryStream)

//The below line used to attach excel file to email. mailer.addAttachment(memoryStream, ‘MYFILE.xlsx’, ‘application/vnd.openxmlformats-officedocument.spreadsheetml.sheet’);

There is any way in Dynamics AX2012 to create an excel file and send the file to email (withouth saving in to the path).

Thanks in advance.

I have the same question (0)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 2,122

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 918 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 646 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans