Results 1 to 6 of 6
  1. #1
    Join Date
    Nov 2004
    Nottingham, england

    Thumbs down Cpanel and Email Filters

    Does anyone use Cpanel?

    I have a website that uses the Cpanel ( control panel system, presumably with WHM provided by the same company.

    I have recently started using their email system to handle email to my domain. I don't know what email system is used.

    In the cpanel interface there is a "email filters" section. The problem is that I don't understand the format for "Destination" section, and the Cpanel documentation ( is extremely inadequete. The only thing I've succeeded in doing is discarding email that matches a certain criteria. I haven't worked out how to do anything else with it, even something as simple as putting it in a specific folder.

    Here is what I'm trying to eventually achieve:
    I have a couple of email addresses ([email protected], [email protected] - that sort of thing) that I tend to give to websites so that if I get spammed they're easily detectable. What I want to do is set a filter so that any emails sent to these addresses is either
    a) marked as spam, so that it will be recognised as such by SpamAssassin (, which is the spam filtering system used, or
    b) placed into the spam folder (where spamassassin send any mail it thinks is spam anyway).

    Does anyone know how to do this please?
    Any help would be greatly appreciated.


  2. #2
    Join Date
    Feb 2005
    Northern VA
    Are these spam addresses POP3 addresses that you set up in CPanel?

    The filters don't mark things as spam. Filters in cpanel merely let you automatically look at messages as they come in and, based on the criteria you set, forward them to another destination.

    If all e-mail that comes into those addresses is spam then why do you need something to mark it, why not just delete any messages that come from those accounts?

    I'm sorry if that didn't help but maybe I'm confused.
    WebsiteMaven - Web Hosting Reviews, Guides, and Advice to Build and Promote your Web Site

  3. #3
    Join Date
    Nov 2004
    Nottingham, england
    Thanks for the reply.

    No they're not actually set up as pop3 address in cpanel. I'd rather not do this.

    The reason I don't just want to delete them is because I need to recieve some email sent to them. You see, I use them for when I register to sites that I don't trust but that require me to confirm my registration from a link in an email they send me, so I need to be able to recieve this first email, but ignore emails to those address in general.

    I know the only things it mentions are deleting, forwarding to another email address, or sending it to a script. I figure at this point, the only way to get it to work is to write a script to place the email in the "spam" folder and make the filter send the email to that. But I don't know how to write such a script. I'm trying to find out though.


  4. #4
    How about a client side solution - forward all messages with "[email protected]" to the address where you want to receive them. Then filter them to the same folder used for Spamassassin email.

    That filter could be done on a webmail interface, or most any POP3 client.

  5. #5
    Join Date
    Nov 2004
    Nottingham, england
    No having my spam in another email account entirely would be very inconvenient. I think it's perfectly possible to just write a script to handle it for me.
    I created a .forward file in the /home/<usename>/ directory and the mail server seems to obey command in here. For example:

    ------- /home/<username>/.forward contents: --------
    \<username>, [email protected], "|/home/<username>/<scriptname>"

    This will send one email to my inbox, send one email to "[email protected]" and also execute the script "scriptname" with the email as an argument. So, with a bit of re-learning perl, i can probably write a perl script to append the contents of the email onto the end of the appropriate folder's mail file.

  6. #6
    Join Date
    Nov 2004
    Nottingham, england
    I have now solved this.
    For anyone coming to this post with a similar problem here's how I did it.

    ".forward" files

    For most unix mail clients a .forward file placed in the user's home directory can be used to specify forwarding destinations.
    You can specify multiple destinations by seperating with commas.

    \username = direct to username's inbox.
    [email protected] = direct to
    "|/<path>/<script>" = direct email to a handling script. Path must be absolute. Inverted commas are required.

    Example (contents of "/home/robin/.forward"):
    # Start of file
    \robin, [email protected], "|/home/robin/script"
    # End of file

    This example will direct copies of any emails to robin's inbox, and [email protected], and also to be handled by the script at /home/robin/script.

    cPanel's Email Forwarding

    I edited the .forward files directly because this seemed a more absolute and general solution, and I don't like cPanel because it's not open source and it has absolutely no documentation of support.

    I assume that you can use cPanel's Email Forwarding setting on the GUI in exactly the same way, just put what would have been the contents of the .forward file into the "destination" box of any rule. This could have made final script (see My Solution at the bottom of the post) simpler because I wouldn't have had to test for the email title.

    email files

    The email files (usually located in "~/mail/", where "~/" is your user's home directory) are written in plaintext format. Therefore to add another email to them you can just append the text for that email (with all the correct headers) onto one of the files (e.g ~/mail/inbox).


    The way I took advantage of this is to have all my emails forwarded to a script. This script can be in any language recognised by the operating system. I used perl.

    When an email is directed to a script all the plaintext defining the email is passed to the script as standard input. Therefore all you have to do is use the script to analyse the text recieved on stdin, edit it if you wish, and append it to the appropriate mail file.

    All I did was set the script to analyse the "To:" line of the email and send it to the spam folder if it detects any key email addresses.

    My Solution

    This is specific to the cPanel unix set up. (replace <username> and <domain> as appropriate):

    ===== Contents of "/home/<username>/.forward" ====

    # Forward File. This determined what to do with incoming email.
    # Multiple commands are comma seperated.
    # '\<username>' = send to user's inbox (as normal)
    # [email protected]' = forward email to this address
    # '|/<path>/<script>' = send email to handling script
    # Example (this will send a copy to inbox & forward to [email protected] & send it to script 'handlingscript':
    # \robin, [email protected], |/home/robin/handlingscript


    ===== Contents of "/home/<username>/filterscript" ===


    # ======= Email Filtering Script ========
    # Filters any emails sent to
    # (spam|trash|junk)@<domain>.com
    # to the spam folder.
    # All other emails are sent to inbox.
    # =========== Activation ================
    # Make sure that the file ".forward" is in
    # ~/ (the user's home directory).
    # Make sure this file contains the line
    # (including the inverted commas):
    # "|/<user-path>/<filename>"
    # where <user-path is the absolute path to
    # the user's home directory, and <filename>
    # is the name of this file.

    @input = @ARGV; #put command line arguments into input array @input
    $file = "/home/<username>/mail/inbox";
    while($line = <STDIN>) {
    $lines[$.] = $line;
    if ($line =~ /^To:.*(spam|trash|junk)\@<domain>.com.*/) {
    $file = "/home/<username>/mail/spam"; # if 'To:' contains any of the emails, change file path to spam folder.

    open OUT, ">>$file"; # open the filestream for writing on $file
    print OUT "\n";
    print OUT @lines; # put all arguments into $file
    close(OUT); # close the filestream
    exit 0;
    Last edited by robinofnotts; 05-22-2005 at 10:37 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts