Jump to content

Server Side E-mail Filtering?

Recommended Posts

Hi all,


I was wondering if it is possible to do procmail-type filtering on TCH's servers to filter incoming e-mail into folders? Obviously I'm aware that you can filter on the client, but I check mail through so many different clients, it gets old having to set up each client to filter accordingly. I know that Exim can do this (see this Exim Documentation Snippet) , but it seems as though we are limited to the forwarding functionality that CPanel's interface provides.


Any help is appreciated.



Link to comment
Share on other sites

I don't have an answer for you right this second, but will lok into it a bit.


I am going to move this into a more appropriate forum, so it will get better visibility as well. Maybe one of the other folks around here will get you an answer faster than I can.

Link to comment
Share on other sites

Procmail is not installed.


And the last I heard, cPanel isnt fully supporting it yet

From what I've read, people have used CPanel to setup forwards to the procmail binary. For example, use the forward interface in CPanel to forward all mail bound for someuser@mytchhost.com to |/path/to/procmail. If procmail were installed, that should force procmail to scan the user's home directory for .procmailrc and follow and rules that are in there. I understand TCH's desire to not support it, but if it were at least installed, then advanced users could utilize it nontheless as an unsupported and unadvertised feature. There really wouldn't be much to *support*.


I really really really really want procmail (or anything similar) to support things like redirecting mail into specific folders for IMAP and such. I have quite a few procmail recipes that I've used for years and now I'm handcuffed on TCH's servers. :)


If procmail will not be *supported* (i.e. installed at all), then is it possible to squeeze more functionality out of the .filter file? I couldn't get it to deliever my mail to anywhere other than my inbox file.

Link to comment
Share on other sites

Ok ... here's my hack:


I set up a filter in CPanel to filter e-mail destined for my e-mail address to |/home/<accountname>/procmail.pl.


procmail.pl is a script I whipped up to try to process incoming e-mail. The following script gives 3 example actions:

* Move e-mail with 'foo' in the subject to the folder 'foo'

* Move e-mail from any address with 'badguy' in it to the 'badguy' folder

* Move e-mail sent TO any address with 'somelist' in it to the 'somelist' folder.


Obviously, in this loop, you can place procmail-esque rules and the entire script takes up only slightly more space than a real .procmailrc file.


# Account name assigned to you by TCH.
# i.e., who do you log in to CPanel with?
$accountname = "<accountname>";
# Domain name used for e-mail
$domainname = "<domain.name>";
# Mail account this is active for
# NOT the entire e-mail address. Just
# the section before the '@' sign.
$mailuser = "<mailuser>";
# Location of your default mail target
# Read in from standard input and check each
# of our regular expressions. Set targets
# accordingly.
while(<STDIN>) {
       if($_ =~ m/^Subject:.*foo/) {
       elsif($_ =~ m/^From:.*badguy/) {
       elsif($_ =~ m/^To:.*somelist/) {
       $buffer .= $_;
# Location of your main mail folder
# Open our target, append our buffer to it, and close it
open(MAILFILE, ">>".$prefix.$target);
print MAILFILE $buffer;


Works like a champ.


:) <----- Me doing the dance of joy.

Link to comment
Share on other sites

  • 1 month later...

@jandafields: Thanks for pointing out this thread! Exactly what I was looking for!


@whoisjohngalt: Forgive my perl-noobness, but I have a question about your 'hack'...


I have three email accounts to my domain. For discussion's sake, let's call them test1, test2, and test3. I am using test3 as my 'catch-all' box.


I've copy/pasted your 'hack', and adjusted the necessary entries to match my situation. In cpanel, I made a filter that will send all email specifically to test1@!there.com to /path/to/test1/procmail.pl. Same with test2, and test3.


All email sent directly to test1, test2, or test3 work fine. Anything else, that should go to the catch-all, bounces with errors.


In the default email address, I set all default email to go to /path/to/test3/procmail.pl.


My question is, should I have sent it to test3@!there.com?


Or did I misread your script worse than I thought? ;)

Link to comment
Share on other sites

In the default email address, I set all default email to go to /path/to/test3/procmail.pl.


Make sure you put the pipe symbol before the script like this:



It won't work without the pipe! Is your script actually in the test3 folder? You may want that script in your home folder so it isn't directly accessible by www.


If you want all unrouted mail to go to test3 without going through the script, put test3@domain.com in the default address box.


If you have code in the script to detect unrouted mail and process it, use:


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...