Delete email attachments older than X days

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jakub Grufik
    Senior Member
    • Aug 2022
    • 361

    Delete email attachments older than X days

    Hello guys, I would love to clean up our system upload directory a bit to save up some space.

    Is there any way how to detect which attachment in the "Administration->Attachments" is an email attachment? I don't want to delete documents linked to the opportunities I would love to delete only email attachments but I have not found any reliable connection between email and attachments to be able to distinguish it.

    Thanks a lot in advance
    Attached Files
  • Jakub Grufik
    Senior Member
    • Aug 2022
    • 361

    #2
    OK I tried to use the filter "Related=email" but it returns just 75k attachments and to me, it seems a bit lower than expected. Do you think I can rely on that?
    Thank you
    Attached Files

    Comment

    • item
      Active Community Member
      • Mar 2017
      • 1476

      #3
      Hi,
      i try upload a print-screen but no luck with bandwitch (holliday).
      in you case, i think if you will delete email and attachment, the best is a "hard attachment delete job" or with email : beforeDeleteHookClassNameList


      important in entity attachment (database field, i don't use email entity, this is just a test email i have write with attachment and save to draft):

      id : id of attachment => name of file in uploadDir

      if file is attached to mail :
      field : attachments
      role : Attachment​
      parentId : id
      parentType : Email
      global : 0

      if file is inline in body :
      field : body
      role : Inline Attachment​
      relatedId : id
      relatedType : Email
      global : 1

      I don't know what is "global".

      you have whith this the base all required info for delete completly : (important : this don't delete Inline Attachment, maybe write another for delete inline attachment)

      PHP Code:
      $email = $this->em->getEntityById('Email', '64ee571fa223bd9d0');
             
      
              $email->loadLinkMultipleField('attachments');
      
              foreach($email->get('attachments') as $attachment){
                   $this->log->error( $attachment->getId() );
      
              }
              // Find Inline Attachment related to this email and delete it
      
      It's just a idea.
      If you could give the project a star on GitHub. EspoCrm believe our work truly deserves more recognition. Thanks.​

      Comment

      • victor
        Active Community Member
        • Aug 2022
        • 727

        #4
        Originally posted by Jakub Grufik
        OK I tried to use the filter "Related=email" but it returns just 75k attachments and to me, it seems a bit lower than expected. Do you think I can rely on that?
        Thank you
        - Create a filter Parent Is Email + Older Than X Days (screenshot 1).
        - Select All Results that you got (screenshot 1).
        - Remove them via Mass Update (screenshot 2).​
        Attached Files
        Last edited by victor; 08-30-2023, 11:56 AM.

        Comment


        • Jakub Grufik
          Jakub Grufik commented
          Editing a comment
          that is exactly how I approached this task ) thanks a lot for confirmation man! have a nice day
      Working...