Skip to main content

Notifications

Dynamics 365 general forum

Export email messages with attachments from Dynamics 365 CRM

Posted on by Microsoft Employee

The constraints for this requirement are as follows:

  • For legislative and/or governance purposes, the organization I am doing this for needs a way to extract email messages (with attachments) from a cloud instance of Dynamics, given a start date and end date;
  • What's important is that the content be made available, not necessarily in a conventient format ("convenient" here I am suggesting is something like a neat MIME-encoded/RFC-822 formatted file, or even proprietary MS .msg format). So, for instance, simply dumping the email body as a file, and the associated attachments as other files, grouped together in a folder somewhere is good enough;
  • The solution needs to be as simple as possible, and should have no technical support needs;
  • Here's the kicker: as much as this solution will necessitate a custom implementation (that is, code), we cannot employ anything outside the constraints of what we currently have in our Azure tenancy, that being: Dynamics 365 with the option of uploading custom plugins and/or custom workflow tasks or currently paid-for PaaS facilities, notably Flow. This eliminates the option of having a console-based application, or even a web app.

I am aware of the fact that one can use Dynamics Advanced Find to export email data (even the body of the email sans attachments) into an Excel file. We do need the email attachments, however.

What is a good way of implementing the above solution?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Export email messages with attachments from Dynamics 365 CRM

    Hello,

    We had the same requirement, Every year the Organization hire seasoned professionals, This is state agency so the positions are public. So there is a Website from where interested professionals can send application along with PDF or DOC format resume (resume is mandatory), these requests comes into CRM directly (means creates a record in entity and attachments are stored in Notes of that record, and everytime an attchment is created we add Subject name "Resume Attached from Webportal" and then Internal Office Admins qualifies for next steps. So, every year those data has to be pruged from CRM system and has to be retruned to library for archives.

    So i ended up creating a Dynamics CRM Attachment Extractor - Utility for this task.

    I decided to build an utility (console application) and exe can be distributed or made available to run. User may double click the exe and application will download the file in the specified path.

    Console application is calling Org service as per the App Settings (CRM Org defined here). It establishes the connection first and then displays the message to use on successful connection and advises user to wait because downloading can take while. FetchXML is querying annotation entity and filtering on filename that contains .pdf,.doc,.docx. Limited querying filters can be added too.

    Application uses C:\AttachmentsForSeasonalJobs location to store the files, if folder does not exist, user have to create one.  After download completes, app displays the “Download complete” message and user can press any key to get out of the command prompt.

    Also, While downlaod I have prefixed the annotationID (GUID) to each attachment name, in case any attachment needs to be traced back. File name is made of annotationID + _ + filename.

    By default an organization service can return only the first five thousand records and page details for the next set of records, if exists. The result entity collection exposes a Boolean attribute called MoreRecords, it will be true if more records available else false. If more records available then you need to use the combo of pagingcookie and page(pagenumber) to retrieve rest of the records.

    Thanks.

  • Suggested answer
    Adrian Begovich Profile Picture
    Adrian Begovich 21,009 Super User 2024 Season 2 on at
    RE: Export email messages with attachments from Dynamics 365 CRM

    Hi Merowig,

    You can extract email attachments by reading data from the activitymimeattachment entity and writing the file content to the local file system. This article explains a method for this.

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... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans