-
Notifications
You must be signed in to change notification settings - Fork 7
Good email server guide with sieve
Following link give full detail on email server configurations.
https://www.c0ffee.net/blog/mail-server-guide/
Sieve: Scripting Your Mailbox
Once of the best things about running your own mail server is being able to script your inbox. Instead of creating filters using a kludgy synax through a web interface, you can literally write programs to determine how to sort your mail. With sieve, regular expressions, if/else control structures, and full message metadata (including headers) are at your disposal.
Recall in the Dovecot section that sieve scripts live in the virtual home directory of each IMAP user. Dovecot's sieve functionality allows a user to have multiple sieve scripts stored on the server, but only one of them can be "active" at any given time. In our configuration, the active sieve script for the user alphonsus would be located at /var/mail/vhosts/example.com/alphonsus/.dovecot.sieve. The .dovecot.sieve file should be a symlink to a script in the sieve directory:
root@awesomebox:/var/mail/vhosts/example.com/alphonsus # ls -l
total 12
lrwxr-xr-x 1 vmail vmail 18 Mar 4 07:35 .dovecot.sieve@ -> sieve/my_cool_script.sieve
-rw-rw-r-- 1 vmail vmail 472 Mar 4 07:38 .dovecot.svbin
drwx------ 4 vmail vmail 512 Aug 15 04:45 mdbox/
drwxrwxr-x 2 vmail vmail 512 Mar 4 07:35 sieve/
If you use a mail client with ManageSieve support (like KMail), these details are handled for you automatically. You can also use sieve-connect, a command-line ManageSieve client. I rarely modify my sieve script, so when I need to make a change I just SSH to my server and edit it in vim.
Let's make a basic sieve script. Open up a root shell and navigate to your IMAP user's virtual home directory under /var/mail/vhosts.
cd /var/mail/vhosts/example.com/user Create the sieve directory if it doesn't already exist:
mkdir sieve Then, create a sieve script. You can name this file whatever you like:
vim sieve/my_awesome_script.sieve Now you're ready to write your script. You can check out some example sieve scripts on the Dovecot wiki here. We'll keep it simple for now.
/var/mail/vhosts/example.com/user/sieve/my_awesome_script.sieve
require ["regex", "fileinto", "imap4flags"];
/* put all of FreeBSD's `periodic` output into Logs folder */
if allof (address :is "from" "[email protected]", header :contains "subject" "run output") {
fileinto "Logs";
stop;
}
/* put online shopping/advertising into Shopping folder */
if anyof (address :is "from" "[email protected]",
address :is :domain "from" "earthfare.com") {
fileinto "Shopping";
stop;
}
I don't believe the sieve script will create any new IMAP folders for you, so be sure to create any folders you need in your mail client first. Now you need to create a symlink so Dovecot knows that this is your "active" script:
ln -s sieve/my_awesome_script.sieve .dovecot.sieve
Make sure your script actually compiles:
sievec .dovecot.sieve Finally, make sure everything is still owned by the vmail user:
chown -R vmail:vmail .dovecot.sieve .dovecot.svbin sieve
Check your mail log the next time you receive an email to verify that Dovecot didn't have any trouble executing your script. You can get as convoluted as you want with sieve—I've seen some cool setups where people call external shell scripts when certain emails are receieved.
Developed by : Lanka Software Foundation