Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Forums / Finance forum / Email Body attachment
Finance forum

Email Body attachment

(0) ShareShare
ReportReport
Posted on by

Hi All,

I am using D365 Finance and Operations (Update 11) version. I want to add a body to invoice emails being sent from the system. I have read some helpful links and am trying to replicate the method mentioned in https://organicax.com/2014/11/26/adding-message-body-text-to-email-destination-for-reports/, but I am facing a lot of issues as I am unable to understand how to add the backend code in D365 FO , for the form. Can anyone please guide me through this ? 

  • Verified answer
    Gurjeet Kaur Mutneza Profile Picture
    45 on at
    RE: Email Body attachment

    Hi,

    It worked, just added one line code in above provided code and it solved my problem.

    emailContract.parmAttachmentFileFormat(SRSReportFileFormat::PDF);

    Thank you

  • Gurjeet Kaur Mutneza Profile Picture
    45 on at
    RE: Email Body attachment

    Hi Martin,

    Your code was really helpful for sending email with ssrs report as attachment, but in my case attachment is going as .csv it is not taking .pdf as extension even after specifying SysUserRoleInfo.pdf attachment in email is coming as SysUserRoleInfo.pdf.csv in D365 for finance and operations.

    Request you to please help me with the same.

  • Verified answer
    Martin Dráb Profile Picture
    232,881 Most Valuable Professional on at
    RE: Email Body attachment

    Then I don't understand how the code helped you. It's for sending e-mails from your code, which isn't related to your requirement. You want to use the normal logic for sending reports via email (which handles attaching the report) and you merely want to change the body; you don't want to reimplement the whole sending logic.

    Therefore you should simply change the body through SrsReportEMailDataContract.parmBody(). 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.pdf');
    
    // 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();
  • Community Member Profile Picture
    on at
    RE: Email Body attachment

    Hi Martin ,

    I think I may have composed the main question in an unclear manner. I will explain the situation here :

    after invoicing a sales order , an email containing the generated invoice as an attachment is sent out to different emails which are defined in print management system settings. This email contains only the email header and the attached invoice. We need to add a body to the same email. So the final product should be : Email containing header + body + pdf of the generated invoice. And I wanted to do the same using print management because the setup of sending out emails is already done in the environment.

    If I use addAttachment() I have to provide the a specific file link there and it will not help as different pdf's are generated everytime and i cannot specify a path. 

    I hope I have made the situation clear :) 

  • Martin Dráb Profile Picture
    232,881 Most Valuable Professional on at
    RE: Email Body attachment

    Can you please elaborate what you mean by "unable to add the attachment"? If you construct the message by yourself using SysMailerMessageBuilder class, you can use its methods addAttachment() and addAttachmentFromFile(). Do you have any problem with it?

    Note that I thought your question was about e-mails created automatically when you print reports with print destination = email, not about sending e-mails by yourself.

  • Community Member Profile Picture
    on at
    RE: Email Body attachment

    This actually helped and the emails are going with a body. But unfortunately I am unable to add the attachment. The main purpose was an invoice email should go along with the generated attachment and a body. Can you help me there ?

  • Suggested answer
    István Orosz Profile Picture
    2,137 on at
    RE: Email Body attachment

    Hi,

    Please take a look at:  How to send emails from code in AX 7

  • Community Member Profile Picture
    on at
    RE: Email Body attachment

    It wasn't . Thank you for pointing it out :)

  • Martin Dráb Profile Picture
    232,881 Most Valuable Professional on at
    RE: Email Body attachment

    Hi Luthful, please separate tags with comma, individual words with spaces and don't prefix tags with #. You attached a single long tag #Email #AttachBody #D365FO #Customization, which clearly wasn't your intention.

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,141 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,881 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans