Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / Email Body attachment
Finance forum
Answered

Email Body attachment

Posted on by Microsoft Employee

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
    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

  • 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
    Martin Dráb 225,490 Super User 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
    Community Member Microsoft Employee 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
    Martin Dráb 225,490 Super User 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
    Community Member Microsoft Employee 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
    István Orosz 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
    Community Member Microsoft Employee on at
    RE: Email Body attachment

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

  • Martin Dráb Profile Picture
    Martin Dráb 225,490 Super User 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.

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,696 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,490 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans