Report printed to e-mail

You can easily send a D365FO report in email just by configuring print destination to Email and setting a few properties.

You can do the same from code, where you can also set the body. You must create an instance of SrsReportEMailDataContract class, fill it values and pass it to SRSPrintDestinationSettings.parmEMailContract(). Here is an example:

SrsReportRunController controller = new SrsReportRunController();
 
controller.parmReportName(ssrsReportStr(SysUserRoleInfo, Report));
controller.parmShowDialog(false);
 
SRSPrintDestinationSettings settings = controller.parmReportContract().parmPrintSettings();
 
settings.printMediumType(SRSPrintMediumType::Email);
settings.fileFormat(SRSReportFileFormat::PDF);
settings.fileName('SysUserRoleInfo.xlsx');
 
// Here we configure the email
SrsReportEMailDataContract emailContract = new SrsReportEMailDataContract();
 
emailContract.parmTo("user@example.com");
emailContract.parmSubject("Security report");
emailContract.parmBody("Hi there! Here is your report.");
 
settings.parmEMailContract(emailContract);
 
controller.startOperation();

4 Comments

  1. Hello Martin,

    Thank you for the post.
    I want to add a field “emailFrom” to the SRSPrintDestinationSettings but this is a framework class, is there another way to achive that ? (email report from a batch job and use another source email adress instead of the user’s address)
    I tried to redirect the report to SysMailerMessageBuilder using the method descriped here :
    https://meritsolutions.com/render-report-memory-stream-d365-aka-ax7/
    But the report attached is never the good one even though the params are good.

    Regards,
    Mourad.

    • Hello,

      The code turns out to be the same: Controller / settings / SRSproxy / SysMailerFactory
      I just had to ajust the missing code from the controller to make it work.

      Thanks.

Leave a Reply

Your email address will not be published.