Skip to main content

dbmail - How to

First of all I would like to share with you all my experience setting up a *testing* mailserver using dbmail as the imap and postfix as the smtp server and of course on Linux. This time I used Slackware Linux 10.2 and this server is actually behind a firewall. For overview what is dbmail, please visit dbmail.org or read previous posting.

Requirements
You need all of these:

  1. mysql server ( I used 4.1.14. This version supports InnoDB)*
  2. dbmail package ( i used version 2.0.7 )
  3. Postfix ( I used version 2.2.7 )
  4. DBMail source (get the latest from dbmail.org)
* Since some DBMail tables can get VERY large (depending on your mailusage) we advise using InnoDB as database storage backend.

Let's get dirty!
Make sure mysql is running. First you'll need to create the DBMail database in MYSQL. You can do this by issueing the following command. This step is only necessary when you do not have a database for DBMail yet. Note that you will be prompted for the MySQL root password.

mysqladmin create dbmail -u root -p

This creates a database with the name "dbmail". Now you have to give a non-root user access to this database. Start the MySQL command-line client as root:

mysql -u root -p

and enter the following command:

GRANT ALL ON dbmail.* to dbmail@localhost identified by ''

Where should be replaced with the password you want for the dbmail user. After this step, the database is ready to be used by the dbmail user. The next step is the creation of the database tables used by DBMail. Log out of the MySQL client and run the following command from the command line. You will have to enter the password you set in the previous step.

mysql -u dbmail dbmail -p <>Copy the dbmail.conf file to /etc and edit the dbmail.conf file and set everything in there to your likeings. Make sure to set your database name, user and host are configured in dbmail.conf. Other options in the configuration file are documented there.

Run configure & make
Run the configure script. This script uses pg_config or mysql_config (depending on --with-mysql or --with-pgsql) to detect where the libraries and include files for these databases are. e.g. when working with PostgreSQL, this is the configure command:

./configure --with-pgsql

For MySQL,

./configure --with-mysql

After running configure, 'make all' will build the executables. Running 'make install' will install the executables in /usr/local/sbin.

Next you will need to create some users into the dbmail mailing sytem. Currently this can be done in two ways. One way is using the dbmail-users utility. The other way is doing it in the database itself. To do it using the dbmail-users utility and do the following:

dbmail-users -a -w -g -m [-s aliases]

clientid can be left 0 (this is if you want certain mailadministrators administer specific groups of mailusers). maxmail is the maximum number of bytes this user may have in his/her mailboxes. 0 is unlimited. Add K or M for kilobytes and megabytes. Aliases are a number of aliases for this user. @domain are domain aliases.

A user always needs to have at least one alias to receive mail, unless the users username is something like foo@bar.org, where bar.org is a domain the mailserver deliveres to.

example:

./dbmail-users -a zamri -w puttycat -g mail -m 25M -s zamri@dude.org zamri@dude.net @net.com

This will create a user zamri, with a password puttycat. It will set zamri's maillimit 25 Mb and all mail for zamri@dude.org, zamri@dude.net and @net.com will be sent to john. The @net.com is a fallback alias. This means that all mail that cannot be delivered to an existing alias for a @net.com address will sent to zamri.

Now for the postfix, i have to add this line in /etc/postfix/master.cf

dbmail-lmtp unix - - n - - lmtp

If you want verbose output in the mail log, add -v to lmtp, like this:

dbmail-lmtp unix - - n - - lmtp -v

Note : This is good for troubleshooting. Don't underestimate it but please note that you get a LOT of output in your logs when using this setting.

Now edit main.cf and add / change the mailbox_transport directive to:

mailbox_transport = dbmail-lmtp:localhost:24 ^
local_transport = dbmail-lmtp:localhost:24 *

*Note: This one to make sure local mail delivery to dbmail.
^Note: This is the step to make sure the mails use dbmail's transport but not including local delivery.

And then set this :

local_recipient_maps =

Note : This step is *VERY* important or mails from outside can not reach your mailbox. See INSTALL.postfix in source for more info.

Afterthat run this commands:

postmap /etc/postfix/transport
postfix reload

Run the dbmail's servers:

dbmail-lmtpd
dbmail-imapd

Make sure postfix and MySQL (or PostgreSQL) are running. Try sending and replying to local users first and if successful, you can then try the same to outside users.

Comments

lousek1992 said…
Hello

Thank you for your post *thumbs up*

One SQL-command is a bit strange:
GRANT ALL ON dbmail.* to dbmail@localhost identified by ''

The '' looks like a " ... maybe a 'password' would be more clear ;)

BR,
lousek
zamri said…
Sorry lousek1992 for that but I have explained it should be password in the ''.

Thanks for the comment anyway. :)

Cheers.

Popular posts from this blog

mplayer-gui error : Error in skin config file

After installing mplayer-gui package, I can't start it.

$ gmplayer MPlayer 1.1-4.8 (C) 2000-2012 MPlayer Team mplayer: could not connect to socket mplayer: No such file or directory Failed to open LIRC support. You will not be able to use your remote control. Error in skin config file on line 6: PNG read error in /usr/share/mplayer/skins/default/main Config file processing error with skin 'default'
After googling a bit, I found out that it was due to the png files in dir /usr/share/mplayer/skins/default. This is the default skin directory. To fix this error, I have to install ImageMagick package because I want to use the convert program to convert all of the png files to format png24. Thus, cd /usr/share/mplayer/skins/default; for FILE in *.png ; do sudo convert $FILE -define png:format=png24 $FILE ; done
Rerun gmplayer and all should be fine.
Have fun!
UPDATE (02-10-2017)

It doesn't work on Ubuntu 16.04 (xenial) but there's a workaround here.

You can update your syst…

Moving your mysql database to another hard disk

Recently, my server's only hard disk was almost full. I bought a new hard disk with bigger size and I decided to just add it as a second hard disk. Since I need to move it to the 2nd hard disk, I need to find a proper way to move the db with minimum downtime. So I googled around and found a solution.
First, I needed to format the 2nd hard disk and I chose xfs as the filesystem. I created 2 partitions using Linux's fdisk for this task. First partition is 10 GB and 2nd one is around 900 GB. That's approximately added up to 1 TB. Then I mounted the 2nd partition in current partition eg /media/hd2 as follows:
mount -t xfs /dev/sdb5 /media/hd2
where /dev/sdb5 is the partition and /media/hd2 is the mounting dir.
Stop mysql db before doing anything:
service mysql stop
Afterthat, I copied the entire db to newly mounted hard disk:
cp -rv /var/lib/mysql /media/hd2
It will take a while if you have huge databases.
Then, change the ownership of the dir to user and group of mysql:
chown -R mysql:…

Transparent proxy with squid 2.6

I have upgraded my squid from 2.5 STABLE13 to 2.6 STABLE18. Transparent proxy is setup differently in this version. You need this directives in squid.conf (usually in /etc or /usr/local/etc or /usr/local/squid/etc, check with your distro).

acl our_networks src 192.168.2.0/24 127.0.0.1
http_access allow our_networks
http_port 192.168.2.1:3128 transparent
always_direct allow all

where 192.168.2.1 is your proxy server IP address.


If you have flushed your iptables, create new rule:

iptables -t nat -A PREROUTING -i eth0 -p tcp –dport 80 -j REDIRECT –to-port 3128

where 3128 is the port where squid is running.
References:
http://www.deckle.co.za/squid-users-guide/Transparent_Caching/Proxy