Email invoice from code

Code
static server void sendInvoiceToMail(CustInvoiceJour _custInvoiceJour,Email _email)
{
    
str                 tempFileName;
    
Args                args;
    
ReportRun           rr;
    
Report              rb;
    
PrintJobSettings    pjs;
    ;

    new 
InteropPermission(InteropKind::ClrInterop).assert();
    
tempFileName System.IO.Path::GetTempFileName();
    
tempFileName += '.pdf';
    
CodeAccessPermission::revertAssert();

    
args = new Args(reportStr(SalesInvoice));
    
args.record(_custInvoiceJour);
    
args.parmEnum(PrintCopyOriginal::OriginalPrint);

    
// Set report run properties
    
rr = new ReportRun(args,'');
    
rr.suppressReportIsEmptyMessage(true);
    
rr.query().interactive(false);

    
// set report properties
    
rb rr.report();
    
rb.interactive(false);

    
// set print job settings
    
pjs rr.printJobSettings();
    
pjs.fileName(tempFileName);
    
pjs.fitToPage(true);
    
// break the report info pages using the height of the current printer's paper
    
pjs.virtualPageHeight(-1);

    
// force PDF printing
    
pjs.format(PrintFormat::PDF);
    
pjs.setTarget(PrintMedium::File);
    
pjs.viewerType(ReportOutputUserType::PDF);

    
// lock the print job settings so can't be changed
    // X++ code int the report may try to change the destination
    // to the screen for example but this does not make
    // sense when running a report here
    
pjs.lockDestinationProperties(true);

    
// Initialize the report
    
rr.init();

    
rr.run();

    new 
InteropPermission(InteropKind::ComInterop).assert();
    new 
SysMailer().quickSend(_email,_email,'Invoice','','',tempFileName);
}
AX versionMicrosoft Dynamics AX 2009
PropertiesCreated by Alex 2015-01-13 12:43:43 (Public)