How to Perdition IMAP/POP3 Proxy – MySQL

•July 7, 2008 • Leave a Comment
Me and my brother was doing a preventive maintenance for one of our clients for their email services. Previously we used traditional UNIX mbox format (which of course from UW-IMAP). With some of the users mailbox size bigger than 1GB, we were forced to do a restructure of the whole email architecture.
The architecture implements 1 server for Perdition IMAP/POP3 proxy and with 2 different mailbox servers. It was hell setting up the whole thing which get me and my brother for almost 4 days with no clue of what to do.
Thank god that we manage to set up everything and it works fine. I was a bit dissappointed because I was unable to explore the possibility of integrating Perdition IMAP proxy and DBMail. I think the integration would be a very stable implementation and email structure.
Procedures:-
  1. Download perdition source file. Compile and furnish with all the required dependencies.
  2. Configure the perdition to work with MySQL by running perdition_mysql_makedb and run through the whole process by providing the information required.
  3. Configure the perdition.conf (if you are compiling from the source, it is usually located under /usr/etc/perdition/perdition.conf) in /etc
  4. Change these for values at # M|map_library FILENAME: header
    •  M /usr/lib/libperditiondb_mysql.so
    • map_library /usr/lib/libperditiondb_mysql.so.0
  5. Enable ‘username_from_database’
  6. Save the config file and restart
  7. Voilla. Your perdition is ready to serve you

How to – Postfix MySQL

•June 21, 2008 • Leave a Comment

Configuration details:-

 + CentOS 5

+ MySQL 5

+ Postfix 2.5


1. Download the latest Postfix from http://www.postfix.org/download.html

 2. Untar the file run make command. Do as the following:-

# make -f Makefile.init makefiles ‘CCARGS=-DHAS_MYSQL -I/usr /include/mysql’ ‘AUXLIBS=-L/usr/lib/mysql -lmysqlclient -lz -lm’
# make install

3. Now to configure Postfix to lookup for aliases in MySQL database

# vi main.cf

Search the following line and change value to:

alias_maps = mysql:/etc/postfix/mysql-aliases.cf

4. Now create a new file named mysql-aliases.cf in default Postfix configuration directory. Usually in /etc/postfix

# vi mysq-aliases.cf

Add the followings:

# mysql config file for local aliases lookup
# The user name and password to log into the mysql server.
user = <database username>
password = <database user password>
# The database name on the servers.
dbname = <database name>
# For Postfix 2.2 and later The SQL query template.
query = SELECT forw_addr FROM mxaliases WHERE alias=”%s”;

5. Restart your postfix

# postfix stop
# postfix start

Optional : You can also configure your Postfix to lookup for local recipients using MySQL database. Below is the example for database lookup and configuration with DBMail

 6. Create a new file named sql-recipients.cf in Postfix configuration directory

# vi sql-recipients.cf

Add the following:

user = <username>
password = <password>
hosts = <dbhost>
dbname = <dbname>
query = SELECT alias FROM dbmail_aliases WHERE alias=’%s’
UNION SELECT userid FROM dbmail_users WHERE userid=’%s’;

7. Configure your main.cf to map to the sql-recipients.cf file:

# vi main.cf

Look for local_recipient_maps and add the following value:

local_recipient_maps = mysql:/etc/postfix/sql-recipients.cf

8. Restart your postfix

# postfix stop
# postfix start

 Reference Site:

DBMail with Postfix : http://www.dbmail.org/dokuwiki/doku.php?id=setup_postfix
Postfix MySQL : http://www.postfix.org/MYSQL_README.html

How to – Disclaimer with alterMIME and Postfix

•June 20, 2008 • Leave a Comment

This is the first time i’ve use web blog to store all my notes. Not really much on myself but I do think this really helps me when I don’t have much time to think about googling the web. Let’s head straigh to our main point. How to setup alterMIME to work with Postfix.

What is alterMIME

alterMIME is a small program which is used to alter your mime-encoded mailpacks as typically received by Inflex, Xamime and AMaViS
[taken from http://www.pldaniels.com/altermime/]

 


My configuration :
+ CentOS 5.0
+ Postfix 2.5
+ altermime 0.3.8


 

 

alterMIME

1. Download alterMIME from http://www.pldaniels.com/altermime

2. Compile alterMIME

# make
# make install

3. Add a filter user

# useradd -r -c “Postfix Filters” -d /var/spool/filter filter

4. Create filter directory for user filter

# mkdir /var/spool/filter
# chown filter:filter /var/spool/filter
# chmod 750 /var/spool/filter

Postfix

5. Change directory to where your Postfix configuration files located. Usually under /etc/postfix

# cd /etc/postfix
# cp master.cf master.cf.ori

6. Modify you master.cf by adding these lines.

smtp inet     n     -     n     -     -     smtpd
-o content_filter=dfilt:
dfilt    unix     -     n     n     -     -     pipe
flags=Rq user=filter argv=/etc/postfix/disclaimer -f ${sender} — ${recipient}

Usually, the first line is already added to the default master.cf file. Look for that line and just add the second line below the entry or you can remark/remove the old entry and just add a new line according to the above configuration.

Should you require only the outbound emails are added with disclaimer, you can do the following:

192.168.1.25:smtp     inet     n     -     n     -     -     smtpd
-o content_filter=dfilt:
127.0.0.1:smtp     inet     n     -     n     -     -     smtpd
-o content_filter=dfilt:
dfilt    unix     -     n     n     -     -     pipe
flags=Rq user=filter argv=/etc/postfix/disclaimer -f ${sender} — ${recipient}

The 192.168.1.25:smtp entry is the IP Address for the outgoing SMTP Server

7. Create a disclaimer file in your default Postfix configuration folder

# vi /etc/postfix/disclaimer.txt
# vi /etc/postfix/disclaimer.html

Add your own text. Example for disclaimer.txt:

This email and its attachments may be confidential and are intended solely for the use of the individual to whom it is addressed. Any views or opinions expressed are solely those of the author and do not necessarily represent those of “[business name]“.
If you are not the intended recipient of this email and its attachments, you must take no action based upon them, nor must you copy or show them to anyone.
Please contact the sender if you believe you have received this email in error.

Example for disclaimer.html:

<hr><br>
This email and its attachments may be confidential and are intended solely for the use of the individual to whom it is addressed. Any views or opinions expressed are solely those of the author and do not necessarily represent those of “[business name]“.
If you are not the intended recipient of this email and its attachments, you must take no action based upon them, nor must you copy or show them to anyone.
Please contact the sender if you believe you have received this email in error.
<a href=”www.abc.com”>ABC Company</a>

8. Create a disclaimer script in your default Postfix configuration directory.

# cd /etc/postfix
# vi disclaimer

Add these lines in your disclaimer script

#!/bin/sh
# Localize these.
INSPECT_DIR=/var/spool/filter
SENDMAIL=/usr/sbin/sendmail
FOLDER_DISCLAIMER=/etc/postfix/

# Exit codes from <sysexits.h>
EX_TEMPFAIL=75
EX_UNAVAILABLE=69

# Clean up when done or when aborting.
trap “rm -f in.$$” 0 1 2 3 15

# Start processing.
cd $INSPECT_DIR || { echo $INSPECT_DIR does not exist; exit $EX_TEMPFAIL; }
TEXT_DISCLAIMER=`grep “[a|A-z|Z]” ${FOLDER_DISCLAIMER}/disclaimer.txt | grep -v “_” | tail -2 | head -1`

cat > in.$$ || { echo Cannot save mail to file; exit $EX_TEMPFAIL; }
nohup grep “${TEXT_DISCLAIMER}” in.$$ > /dev/null 2>&1

if [ ! "$" = 0 ]; then
/usr/local/bin/altermime –input=in.$$ –disclaimer=${FOLDER_DISCLAIMER}/disclaimer.txt –disclaimer-html=${FOLDER_DISCLAIMER/disclaimer.txt –xheader=”X-Copyrighted-Material: Please visit http://www.company.com/privacy.htm” || { echo Message content rejected; exit $EX_UNAVAILABLE; }
fi

$SENDMAIL “$@” < in.$$
exit $?

9. Set permission for the disclaimer script

# chgrp filter /etc/postfix/disclaimer
# chmod 750 /etc/postfix/disclaimer

10. Now we need to restart Postfix

# postfix stop
# postfix start

Reference Site:

Zimbra – alterMIME and Postfix : http://wiki.zimbra.com/index.php?title=Adding_a_disclaimer_(altermime)_or_footer

 
Follow

Get every new post delivered to your Inbox.