How do I filter my email? (Server-Side)


Disclaimer: You should only attempt this if you feel confident with the command line. If this filter is implemented incorrectly it could cause problems recieving emails.

Note: You should remote ssh into either linux.engr.ucsb.edu or csil.cs.ucsb.edu and run these commands from there.

1.Open up your file editor of choice, in this example we will be using nano.

cd ~/Documents

nano mailFilter.txt

This will create a text file called "mailFilter.txt" in your Documents folder where we can write the mail filtering script. You can create this file wherever you like and call it whatever you want.

2. Type the following into the first line of the file.

require ["fileinto","include"];

If you would like your email account vacation message to be able to be set from the ECI Account Maintenance Page (https://accounts.engr.ucsb.edu/), add the following line below. You can add this line even if you are not activating the message now, but just want the ability to set it from the Maintenance Page later.

include :optional "vacation-web";

3. For each of the following rules, append the examples with the information desired substituted into the code.

Example 1: Filter all mail coming from john.smith@example.com into a folder called "JSmith".

if address :is "from" "john.smith@example.com"

{

fileinto "JSmith";

}

Example 2: Filter all mail coming from john.smith@example.com and jane.doe@example.com into a folder called "TeamProject".

if address :is "from" ["john.smith@example.com", "jane.doe@example.com"]

{

fileinto "TeamProject";

}

Example 3: Filter all mail that has a subject containing "Summer 2014" into a folder called "Summer14".

if header :contains "subject" "Summer 2014"

{

fileinto "Summer14";

}

Example 4: Filter all mail coming from an address at engineering.ucsb.edu into a folder called "Engineering".

if address :is :domain "to" "engineering.ucsb.edu"

{

fileinto "Engineering";

}

You can add as many email addresses as you like to the list, just add a comma, a space, and the email address in quotations before the end square bracket, just like in example 2.

4. Add as many instances of those examples for as many rules as you would like to the file.

If you would like to add a comment, you can insert a new line and add a "#" at the beginning of the line.

#This is a comment.

Complete File Example: Rule 1: Filter all mail from john.smith@example.com into a folder called "JSmith". Rule 2: Filter all mail from john.deer@example.com and bob.jones@example.com into a folder called "Project2".

require ["fileinto","include"];

#Include CoE Vacation Message if it is activated.

include :optional "vacation-web";

#Filter Mail From John Smith

if address :is "from" "john.smith@example.com"

{

fileinto "JSmith";

}

#Team Project Filter

if address :is "from" ["john.smith@example.com", "jane.doe@example.com"]

{

fileinto "TeamProject";

}

5. You should now save and close the file. If you are using nano, type control-x, then when it asks you to save the modified buffer, type the letter y to respond "yes". You should now be back at the terminal prompt.

6. To ensure that we are in the Documents folder, or the folder that you created the file in, enter:

pwd

If you are not, you can return to the documents folder by entering:

cd ~/Documents

7. At the terminal prompt, enter the following and replace username with your username:

sieve-connect --server 128.111.53.8 --port 4190 -u username --notlsverify

Note: Once you are at the ">" prompt, you can type "help" and press enter to view your options.

8. Enter the following at the prompt:

upload mailFilter.txt

Note: You can also upload a new version of a script and it will overwrite the old one.

9. To verify that the script was uploaded enter:

list

Make sure that the script appears in the result.

10. Activate the script by entering the following:

activate mailFilter.txt

11. Verify that the script was activated by running the list command one more time, it should say
"ACTIVE" next to the script name.

list

12. Now enter:

quit

13. You should now be back at the terminal prompt. Enter:

exit

You are now done.

Note: For more information you can look up online how to write Sieve scripts.

Tags: mail
Last update:
2014-01-11 02:22
Author:
Brian Sandler
Revision:
1.4
Average rating: 4 (1 Vote)

You cannot comment on this entry

Chuck Norris has counted to infinity. Twice.