Share |

Thursday, January 14, 2010

How to send a email with attached report from Dynamics NAV

You must previously configure the SMTP, by mean Form 409.

//Create message
cu400.CreateMessage('Sender','sender@mycompany.com',
'recipient1@yourcompany.com;recipient2@yourcompany.com',
'Subject','Body <b>in HTML</b> format.<BR>Regards.',TRUE);
//Generate the report in html format
rpt101.SAVEASHTML(TEMPORARYPATH + 'report101.html');
//Attach file in to email
cu400.AddAttachment(TEMPORARYPATH + 'report101.html');
//Send email
cu400.Send;
//Erase file
ERASE(TEMPORARYPATH + 'report101.html');