locked
Keep email message but delete attachment RRS feed

  • Question

  • Using CRM 2011 Online

    We have an issue - when we send out large attachments through the email router a copy of the attachment gets stored in the database.

    We need to keep the email but remove/delete the attachments.

    It appears that we will need to write a plugin to be able to accomplish this. Has anyone created such a plugin?

    If there is a way to send the email/attachment but not store the attachment? That would accomplish our goal.

    If there is a way through workflow or the bulk delete tool that would also be sufficient.

    Anyone interested in writing such a plugin please let me know.

    Thanks

    Doug


    Doug Steinschneider DCS Group


    • Edited by dcsgroup Monday, June 11, 2012 4:11 PM
    Monday, June 11, 2012 4:10 PM

Answers

  • Follow up for this questin I posted June 2012:

    For one client I purchased MTC Email Attachment Remover for $500. It has a small solution that is for its license. The app itself is downloaded and extracted to a folder and run as a stand alone. It's only filters are date range and size greater than X. The client wanted to remove all attachments so in a brief 20 minute session to install and run the software I was able to keep the emails and remove all attachments. This can be run any time to catch up with newer attachments.

    Sven Vanoirbeek in a post below recommend Jason Lattimer's Internal Emal Helpers on Codeplex:

    Jason Lattimer Internal Email Helpers

    This solution adds a custom workflow section called LAT, one of the choices is Remove Attachment Keep Email. I created a new workflow and set the size greater than 10,000 bytes and False to "Create Note (indicating attachment removed).

    Then I simply created an advanced find for Activity Type Email with Date Created more than X months ago and set related record attachment to be the size in bytes I wished to remove.

    The one huge drawback is that the Activity grid even in the CRM for Outlook is limited to 250 records so you have to keep refreshing the view and select all the records and choose to apply the workflow.

    If anyone requests I am willing to create a help sheet on how to set up this workflow and remove swaths of email attachments.


    Doug Steinschneider DCS Group


    • Marked as answer by dcsgroup Monday, September 30, 2013 4:45 PM
    • Edited by dcsgroup Monday, September 30, 2013 4:51 PM
    Monday, September 30, 2013 4:44 PM

All replies

  • You could use the bulk delete option for this and create a filter for attachments with filesize > XXX

    Carsten Groth http://carstengroth.wordpress.com Microsoft Dynamics Certified Technology Specialist

    Monday, June 11, 2012 4:51 PM
  • Hi Carsten,

    Won't we lose the email itself if we use the bulk delete option? I'll refine the mandate:

    We need to remove/delete attachments identified by name (email subject has same name) but keep the original mesage the attachment was "attached" to.

    Thanks,

    Doug


    Doug Steinschneider DCS Group


    • Edited by dcsgroup Monday, June 11, 2012 5:32 PM
    Monday, June 11, 2012 5:32 PM
  • Doug, you can follow Carsten's suggestion to delete the Notes that are a file attachment bigger than X MB. He's not suggestion that you use the Bulk Delete feature to delete the email message.

    Neil Benson, CRM Addict and MVP at Slalom Consulting. Find me on Twitter. Join over 20,000 other CRM professionals on the Microsoft Dynamics CRM group on LinkedIn.

    Monday, June 11, 2012 5:59 PM
    Moderator
  • The only way I've been able to look up the email attachment objects in the system by the name of the attachment is through Email Messages with related Email Attachments and then paste in the attachment name for File Name equals. At that point if I delete it deletes the email message and the attachment. I need to keep the email message (closed activity with subject and body). Sorry I'm not following on recommended method.


    Doug Steinschneider DCS Group

    • Proposed as answer by Scott Scribner Thursday, January 11, 2018 2:06 AM
    Monday, June 11, 2012 7:45 PM
  • If I do an advanced find on Notes and put in the filename equals TestBigPDF.pdf nothing returns. The attachments were attached to an email template (usually 1-3 attachments of 1-2MB in size) and then sent out to marketing list contacts.

    These attachments are not needed in record and using up a lot of storage. Again we need to keep a record that files with that name were sent on that day along with the email body.

    Thanks.


    Doug Steinschneider DCS Group

    Monday, June 11, 2012 7:51 PM
  • Monday, June 11, 2012 8:10 PM
  • Hi Sven,

    Thanks for post, for each filename there are about 2000 messages that need 1-3 attachments removed. From the replies here and my research I'm concluding that I will need to commission an MSCRM dev to build us a app/plugin that will allow us to submit a filename and have it remove all attachments named with that filename.

    Doug


    Doug Steinschneider DCS Group

    Monday, June 11, 2012 8:41 PM
  • Doug, you can follow Carsten's suggestion to delete the Notes that are a file attachment bigger than X MB. He's not suggestion that you use the Bulk Delete feature to delete the email message.

    Neil Benson, CRM Addict and MVP at Slalom Consulting. Find me on Twitter. Join over 20,000 other CRM professionals on the Microsoft Dynamics CRM group on LinkedIn.

    Hi Neil,

    When I did advanced find on Notes with a file attachment and put in filename equals the attachment I want to remove they didn't appear. They do appear when I do an advanced find on email messages and then pick related Attachments and then Filename equals "Example_file.pdf". But then any delete actions are against the entire email message and attachments.

    Thanks,

    Doug


    Doug Steinschneider DCS Group


    • Edited by dcsgroup Tuesday, June 12, 2012 1:48 PM
    Tuesday, June 12, 2012 1:47 PM
  • We are having the same issue here.

    We want to delete just the attachment of the emails we currently have in the system.

    How can we do this without deleting the entire email message?  We need to keep the email messages but delete just the attachments.

    Wednesday, August 22, 2012 2:55 PM
  • You will find sample code in the sdk

    SampleCode\CS\BusinessDataModel\Activities\CRUDEmailAttachments.cs


    Carsten Groth http://carstengroth.wordpress.com Microsoft Dynamics Certified Technology Specialist CRM Online 30 Tage kostenfrei testen – http://crm.dynamics.com/de-de/trial-overview

    Wednesday, August 22, 2012 6:11 PM
  • Hi Carsten,

    Thanks for the sample code location in the SDK. I'll take a look at it and come back and mark this as an answer along with my notes on how I was able to implement it.

    Doug


    Doug Steinschneider DCS Group

    Wednesday, August 22, 2012 7:20 PM
  • Hi James,

    Are you working out of the Jersey City office? I'm in CT but have a buch of clients in midtown.  I've been looking into creating a small solution for this. I'm thinking of collecting other people who need this in a KickStarter type effort (maybe that's the place to do this?) and then having a good developer (one of the author's of a Microsoft Press book on MS CRM emailed me that he is interested in developing solution). Please contact me at dougs(at)dcsgroupllc(dot)com if you're interested.

    Doug


    Doug Steinschneider DCS Group

    Wednesday, August 22, 2012 7:36 PM
  • Doug,

    Were you able to find the solution? We are eager to implement this asap in our CRM... 

    We have exact issue as well, need to delete all of the attachments, but keep the email record.

    Thank you!

    Anya


    --- ATS2011

    Thursday, September 20, 2012 6:53 PM
  • Any solutions to this?  Every user of our system was just notified that we are at 80% of our storage capacity.  Thanks!
    Friday, May 24, 2013 8:30 PM
  • I can't help thinking that you're looking for a solution to a self-made problem instead of fixing the root cause of the problem. The root cause of the problem is that your users are using bad practice: attaching files to mass emails. These files clutter your CRM database, your email sever, your recepients' email servers and e-mail clients; they reduce the deliverability of your emails and could make your organization unpopular with some recipients.

    Once you fix your current issue of a cluttered up CRM database, is there any chance you could change your users' habits and have them include links to files instead of attached files in their mass emails?


    Neil Benson, CRM Addict and MVP at Slalom Consulting. Find me on Twitter. Join over 20,000 other CRM professionals on the Microsoft Dynamics CRM group on LinkedIn.

    Friday, May 24, 2013 9:44 PM
    Moderator
  • To delete the offending files, you can set up a recurring bulk delete job:

    Delete Notes where 'Is Document' equals Yes and 'File Size' is greater than x (where x represents your maximum file size in kb).

    Hope this helps.


    Neil Benson, CRM Addict and MVP at Slalom Consulting. Find me on Twitter. Join over 20,000 other CRM professionals on the Microsoft Dynamics CRM group on LinkedIn.

    Friday, May 24, 2013 9:54 PM
    Moderator
  • Neil, I don't think that approach would work. The email attachments are not listed as notes if you perform a search in Advanced Find. Attachments to any other entity can be found that way, but email attachments seem to be filtered out by CRM, even though they physically must reside in the same database table. Since AF won't find them, I'd assume the bulk deletion job won't touch these records either.

    Jukka Niiranen - My blog: Surviving CRM - Follow @jukkan on Twitter

    Saturday, May 25, 2013 10:28 PM
  • Hi all,

    The email attachments are not stored in the same table as the normal attachments are stored in Annotation however the email attachments are stored in activitymime attachment. So different table. If you want to search the email attachment you could the activitymime attcahment table .

    Sol: Solution for your Problem is Writing a Plugin that would rename the attchment or download it fro that Place may store it on HD and then Delete it . Or rename and then delete straight away. In below code is for remaning and downloading.Refer sdk.

    public static void UpdateActivityMimeAttachment(XrmServiceContext xrm, int skip, int take)
            {
                try
                {
                    IEnumerable<ActivityMimeAttachment> EmailAttachments = (from aa in xrm.ActivityMimeAttachmentSet
                                                                            select aa).Skip(skip).Take(take);
                    foreach (ActivityMimeAttachment entity in EmailAttachments)
                    {
                        if (entity.FileName != null)
                        {
                            if (!entity.Body.StartsWith("file://"))
                            {
                                using (FileStream fileStream = new FileStream(@"\\*****\MSCRMAttachments\crm\" + entity.ActivityMimeAttachmentId.ToString() + "_" + entity.FileName.ToString(), FileMode.OpenOrCreate))
                                {
                                    byte[] fileContent = Convert.FromBase64String(entity.Body);
                                    fileStream.Write(fileContent, 0, fileContent.Length);
                                }
                                entity.Body = @"file://\\******\MSCRMAttachments\crm\" + entity.ActivityMimeAttachmentId.ToString() + "_" + entity.FileName.ToString();
                                xrm.UpdateObject(entity);
                                xrm.SaveChanges();                          

                            }
                        }
                    }
                }

    Please mark it as answer if u find it relevant.

    Monday, May 27, 2013 6:28 AM
  • I can't help thinking that you're looking for a solution to a self-made problem instead of fixing the root cause of the problem. The root cause of the problem is that your users are using bad practice: attaching files to mass emails. These files clutter your CRM database, your email sever, your recepients' email servers and e-mail clients; they reduce the deliverability of your emails and could make your organization unpopular with some recipients.

    Once you fix your current issue of a cluttered up CRM database, is there any chance you could change your users' habits and have them include links to files instead of attached files in their mass emails?


    Neil Benson, CRM Addict and MVP at Slalom Consulting. Find me on Twitter. Join over 20,000 other CRM professionals on the Microsoft Dynamics CRM group on LinkedIn.

    Hi Neil - Good comment - We did move over to Mail Chimp and use PowerMailChimp to integrate. I still have to get rid of the old attachments. I'm experimenting with a workflow solution by Jason Lattimer than can delete attachments while preserving the emails.

    Doug Steinschneider DCS Group

    Thursday, September 26, 2013 2:59 AM
  • Follow up for this questin I posted June 2012:

    For one client I purchased MTC Email Attachment Remover for $500. It has a small solution that is for its license. The app itself is downloaded and extracted to a folder and run as a stand alone. It's only filters are date range and size greater than X. The client wanted to remove all attachments so in a brief 20 minute session to install and run the software I was able to keep the emails and remove all attachments. This can be run any time to catch up with newer attachments.

    Sven Vanoirbeek in a post below recommend Jason Lattimer's Internal Emal Helpers on Codeplex:

    Jason Lattimer Internal Email Helpers

    This solution adds a custom workflow section called LAT, one of the choices is Remove Attachment Keep Email. I created a new workflow and set the size greater than 10,000 bytes and False to "Create Note (indicating attachment removed).

    Then I simply created an advanced find for Activity Type Email with Date Created more than X months ago and set related record attachment to be the size in bytes I wished to remove.

    The one huge drawback is that the Activity grid even in the CRM for Outlook is limited to 250 records so you have to keep refreshing the view and select all the records and choose to apply the workflow.

    If anyone requests I am willing to create a help sheet on how to set up this workflow and remove swaths of email attachments.


    Doug Steinschneider DCS Group


    • Marked as answer by dcsgroup Monday, September 30, 2013 4:45 PM
    • Edited by dcsgroup Monday, September 30, 2013 4:51 PM
    Monday, September 30, 2013 4:44 PM
  • Doug, you could try one of these community provided solutions for scheduling recurring workflow processes to run on a set of records specified in an entity view FetchXML statement. This way you could have Jason's custom workflow activity and have it run every X days for emails that are older than X months, without having to go through the records 250 at a time and initiate the on demand workflow process manually.

    Yaniv Arditi: Asynchronous Batch Process Pattern
    http://blogs.microsoft.co.il/blogs/rdt/archive/2012/09/30/asynchronous-batch-process-pattern-part-2.aspx

    Lucas Alexander: Scheduling recurring Dynamics CRM workflows with FetchXML
    http://www.alexanderdevelopment.net/post/2013/05/19/Scheduling-recurring-Dynamics-CRM-workflows-with-FetchXML#.UZprKrUqzwA


    Jukka Niiranen - My blog: Surviving CRM - Follow @jukkan on Twitter

    Tuesday, October 1, 2013 7:38 AM