Skip to main content

Automatically delete emails matching the string "lan.scan@"

Comments

8 comments

  • cPRex Jurassic Moderator
    Hey there! While I don't have a ready-made script for this, you'll likely want to use something similar to this to get all the mail directories: find /home/*/mail/ as the "find" command can use wildcards to get information across multiple accounts.
    0
  • MoviHussein
    Hey there! While I don't have a ready-made script for this, you'll likely want to use something similar to this to get all the mail directories: find /home/*/mail/ as the "find" command can use wildcards to get information across multiple accounts.

    I have looked into that command but how would you for example make it find all matching email addresses that match the string "scan" for example instead of the focus on 1 email. Thank you for the reply.
    0
  • cPRex Jurassic Moderator
    Find does all that work for you. For example, this works well to find all the .spam folders on the system: # find /home/*/mail/*/ -type d -name ".spam" /home/user1/mail/domain1.com/email1/.spam /home/user1/mail/domain1.com/email2/.spam /home/user2/mail/domain2.com/email1/.spam /home/user3/mail/domain3.com/email1/.spam /home/user4/mail/domain4.com/email1/.spam
    0
  • MoviHussein
    Find does all that work for you. For example, this works well to find all the .spam folders on the system: # find /home/*/mail/*/ -type d -name ".spam" /home/user1/mail/domain1.com/email1/.spam /home/user1/mail/domain1.com/email2/.spam /home/user2/mail/domain2.com/email1/.spam /home/user3/mail/domain3.com/email1/.spam /home/user4/mail/domain4.com/email1/.spam

    Thank for the example as it helped me find the exact locations for each file. The code below works with deleting each email find /home/%user/mail/example.com/mailuser/.spam -type f -mtime +14 -exec rm {} \;
    I can now do this for each email through cron job but if possible is there any way where instead of putting the exact "mailuser", I can do this command of deleting spam folders for specific set of emails that start with "string". An example of what I mean is if I have 5 deferent emails such as link.email1@domain.com link.email2@domain.com link.email3@domain.com testing@domain.com testing@domain.com Am I able to find all email that start with "link" and delete the spam folder of those emails every 2 weeks? or if there is a way to make a script that will find all matching emails with the string "link" and then the code above can run and delete spam (or other types of folders) folders every 2 weeks? Thanks.
    0
  • cPRex Jurassic Moderator
    I'm not sure there's going to be an easy way to pull specific messages by subject or address, as they don't get stored with a helpful filename.
    0
  • MoviHussein
    I'm not sure there's going to be an easy way to pull specific messages by subject or address, as they don't get stored with a helpful filename.

    Ok, I will try to look around for such a command and if I find a solution to that, I will post it here. Thank you.
    0
  • MoviHussein
    Ok, I will try to look around for such a command and if I find a solution to that, I will post it here. Thank you.

    I have found a way to find all emails and delete "Sent" emails after a certain amount of time with the code below find /home/user/mail/domain/scan*/.Sent -type f -mtime +14 -exec rm {} \;
    This allows me to delete all the sent emails older than 2 weeks on every emails that matches (or starts) with "scan". The only issue I am having now is that my junk emails are not getting deleted with using this code find /home/user/mail/domain/scan*/.Junk -type f -mtime +14 -exec rm {} \;
    While testing the codes I tried to move a email from my inbox to junk and run the code but It would not do anything. Thank you.
    0
  • cPRex Jurassic Moderator
    Try running the commands without the "-exec rm {} \;" portion of the code as that will just print a list of results. You can then modify the command until you get the expected results before passing the "rm" portion.
    0

Please sign in to leave a comment.