You are on page 1of 16

Virtual Users And Domains With Postfix, Courier, ... http://www.howtoforge.com/virtual-users-domains-...

Virtualization Poll

Options For This Howto


VMware Images:

V irtual U s ers A nd
D omains With
P os tfix, C ourier,
M ySQ L A nd
SquirrelM ail
(U buntu 8 .0 4
L T S) (5 2 4 .9 M B)
(0 5 /1 5 /2 0 0 8 )

V M ware I mage
I mport G uide
L is t of all V M ware
I mages
Free Support
P aid Support

Navigation
H owtos
L inux
C entO S
D ebian
Fedora
Kernel
M andriva
P C LinuxO S
SuSE
U buntu
A pac he
Bac kup

1 of 16 11/30/09 12:04
Virtual Users And Domains With Postfix, Courier, ... http://www.howtoforge.com/virtual-users-domains-...

C ontrol P anels
DNS
D es ktop
E mail
A nti-Spam/V irus
P os tfix
P roc mail
Sendmail
FT P
H igh-A vailability
L ighttpd
M onitoring
M ySQ L
P rogramming
C /C ++
P HP
Samba
Sec urity
A nti-Spam/V irus
V irtualization
O ther
FreeBSD
C ommerc ial
M ini-H owtos
Forums
C ontribute
Subs c ription
L ogin
Site M ap/RSS Feeds

User login
U s ername:

P as s word:

Remember M e?

C reate a new ac c ount


Reques t new pas s word

Ads by Google
Free Domains
Postf ix
Conf igure Exim
Qmail Amav is

Who's online

2 of 16 11/30/09 12:04
Virtual Users And Domains With Postfix, Courier, ... http://www.howtoforge.com/virtual-users-domains-...

T here are c urrently 7 us ers and 2 7 7 1 gues ts online.

HowtoForge Forums
Sell C vv G ood and
fres h, pleas e
purc has e my :X
s ell C vv G ood and
fres h, pleas e
purc has e my :X
how to run
inotifywait
bac kground
Res tarting O penBSD
Sec ure Shell
s erver s s hd
L inux ldap bind
windows ad
L dap from windows
to linux
pos tfix/s quirrelma
il with plugin ...
G odaddy and
N ames ervers
H ow to Run a V ideo
at the s tart
unattended?
L oc al T es ting
Server Setup

News
D is tro Review: O penSU SE 1 1 .2
KD E C ommunity Forums A nnounc e the C ontinuation of Klas s room
D RM C hange C ontinues T o C aus e D ebate
T he P erfec t D es ktop - Fedora 1 2 i6 8 6 (G N O M E )
Stream mus ic wireles s ely us ing P uls eA udio s erver
M us ic A lbum C overs A nd P ic ture P reviews A s Folder T humbnails I n N autilus
L inux M int 8 final releas ed
Finding files and doc uments with Rec oll
When O pen Sourc e M eets C los ed M inds
Strange I deas A bout Freedom of Speec h

more

Recent comments
boot problem after ins tall php5 pakage
1 4 hours 5 1 min ago
T hanks man
1 4 hours 5 8 min ago

3 of 16 11/30/09 12:04
Virtual Users And Domains With Postfix, Courier, ... http://www.howtoforge.com/virtual-users-domains-...

s quiremail not working


1 5 hours 2 3 min ago
Re: Sec urity c ons ideration - D N S
1 9 hours 6 min ago
Re: C hillifire™ H ots pot s olution - Run one hots pot or an entir
1 9 hours 2 5 min ago
openvz
2 2 hours 3 1 min ago
problems with pam
1 day 5 hours ago
Re: When I ins talled and s tarted
1 day 1 5 hours ago
Re: s ubvers ion tutoria;
2 days 3 hours ago
thanks everything woked
2 days 3 hours ago

Newsletter
Subscribe to
HowtoForge
Newsletter
and s tay informed
about our lates t
H O WT O s and
projec ts .
enter email address

(T o uns ubs c ribe


from our news letter,
vis it this link.)

Syndicate

H owtoForge Feed for Fac ebook®


"Facebook" is a registered trademark of Facebook, Inc. All rights reserved.

English | Deutsch | Site Map/RSS Feeds | Advertise


DunyaTe k nolojis i.com Se ndm ail Anti Spam Linux Ins tallation
Bilişim Teknolojilerini başarıyla Full content scan during SMTP No The f ree and easy w ay to install
öğrenmek için en büyük kaynağınız. w aiting and no more spam Linux Ubuntu in 7 steps. View
www.dunyateknolojisi.com www.ArmResearch.com now !
bM ig hty.informationweek.com/linux

You are here: Home » Virtual Users And Domains With Postfix, Courier, MySQL And SquirrelMail (Ubuntu 8.04 LTS) » Virtual Users And

4 of 16 11/30/09 12:04
Virtual Users And Domains With Postfix, Courier, ... http://www.howtoforge.com/virtual-users-domains-...

Domains With Postfix, Courier, MySQL And SquirrelMail (Ubuntu 8.04 LTS) - Page 2

Virtual Users And Domains With Postfix, Courier, MySQL And SquirrelMail (Ubuntu
8.04 LTS) - Page 2

Do you like HowtoForge? Please consider supporting us by becoming a


subscriber.
Submitted by falko (Contact Author) (Forums) on Tue, 2008-05-20 17:19. ::
Hot Trends Computers
0
Black Friday Fly ers Domain Hosting
Black Friday Online Domain Registration N ow we have to tell P os tfix where it c an find all
tweet
Black Friday Free Internet the information in the databas e. T herefore we
Black Friday Specials Firewall have to c reate s ix text files . Y ou will notic e that I tell
Toy s R Us Black Printers P os tfix to c onnec t to M ySQ L on the I P addres s
Electronics Entertainment 127.0.0.1 ins tead of localhost. T his is bec aus e P os tfix is
DVDs Books running in a c hroot jail and does not have ac c es s to the
Digital Cameras Concert Tickets M ySQ L s oc ket whic h it would try to c onnec t if I told
Laptops Games
P os tfix to us e localhost. I f I us e 127.0.0.1 P os tfix us es
Mobile Phones Fantasy Football
MP3 Play ers MP3 Download T C P networking to c onnec t to M ySQ L whic h is no
Video Games Toy s problem even in a c hroot jail (the alternative would be to
Chitika | Premium Sponsored Results move the M ySQ L s oc ket into the c hroot jail whic h
c aus es s ome other problems ).

P leas e make s ure that /etc/mysql/my.cnf c ontains the following line:

vi /etc/mysql/my.cnf

[...]
bind-address = 127.0.0.1
[...]

I f you had to modify /etc/mysql/my.cnf, pleas e res tart M ySQ L now:

/etc/init.d/mysql restart

Run

5 of 16 11/30/09 12:04
Virtual Users And Domains With Postfix, Courier, ... http://www.howtoforge.com/virtual-users-domains-...

netstat -tap | grep mysql

to make s ure that M ySQ L is lis tening on 127.0.0.1 (localhost.localdomain):

root@server1:/usr/src# netstat -tap | grep mysql


tcp 0 0 localhost.localdo:mysql *:* LISTEN 6177/mysqld
root@server1:/usr/src#

N ow let's c reate our s ix text files .

vi /etc/postfix/mysql-virtual_domains.cf

user = mail_admin
password = mail_admin_password
dbname = mail
query = SELECT domain AS virtual FROM domains WHERE dom
hosts = 127.0.0.1

vi /etc/postfix/mysql-virtual_forwardings.cf

user = mail_admin
password = mail_admin_password
dbname = mail
query = SELECT destination FROM forwardings WHERE sourc
hosts = 127.0.0.1

vi /etc/postfix/mysql-virtual_mailboxes.cf

6 of 16 11/30/09 12:04
Virtual Users And Domains With Postfix, Courier, ... http://www.howtoforge.com/virtual-users-domains-...

user = mail_admin
password = mail_admin_password
dbname = mail
query = SELECT CONCAT(SUBSTRING_INDEX(email,'@',-1),'/'
hosts = 127.0.0.1

vi /etc/postfix/mysql-virtual_email2email.cf

user = mail_admin
password = mail_admin_password
dbname = mail
query = SELECT email FROM users WHERE email='%s'
hosts = 127.0.0.1

vi /etc/postfix/mysql-virtual_transports.cf

user = mail_admin
password = mail_admin_password
dbname = mail
query = SELECT transport FROM transport WHERE domain='%
hosts = 127.0.0.1

7 of 16 11/30/09 12:04
Virtual Users And Domains With Postfix, Courier, ... http://www.howtoforge.com/virtual-users-domains-...

vi /etc/postfix/mysql-virtual_mailbox_limit_maps.cf

user = mail_admin
password = mail_admin_password
dbname = mail
query = SELECT quota FROM users WHERE email='%s'
hosts = 127.0.0.1

T hen c hange the permis s ions and the group of thes e files :

chmod o= /etc/postfix/mysql-virtual_*.cf
chgrp postfix /etc/postfix/mysql-virtual_*.cf

N ow we c reate a us er and group c alled vmail with the home direc tory /home/vmail. T his is where all
mail boxes will be s tored.

groupadd -g 5000 vmail


useradd -g vmail -u 5000 vmail -d /home/vmail -m

N ext we do s ome P os tfix c onfiguration. Go sur e that y ou r epl ac e ser v er 1 .ex ampl e.c om w i th a v al i d FQDN ,
other w i se y our Postf i x mi ght not w or k pr oper l y !

postconf -e 'myhostname = server1.example.com'


postconf -e 'mydestination = server1.example.com, localhost, localhost.localdomain'
postconf -e 'mynetworks = 127.0.0.0/8'
postconf -e 'virtual_alias_domains ='
postconf -e 'virtual_alias_maps = proxy:mysql:/etc/postfix/mysql-virtual_forwardings.cf,
mysql:/etc/postfix/mysql-virtual_email2email.cf'

8 of 16 11/30/09 12:04
Virtual Users And Domains With Postfix, Courier, ... http://www.howtoforge.com/virtual-users-domains-...

postconf -e 'virtual_mailbox_domains = proxy:mysql:/etc/postfix/mysql-virtual_domains.cf'


postconf -e 'virtual_mailbox_maps = proxy:mysql:/etc/postfix/mysql-virtual_mailboxes.cf'
postconf -e 'virtual_mailbox_base = /home/vmail'
postconf -e 'virtual_uid_maps = static:5000'
postconf -e 'virtual_gid_maps = static:5000'
postconf -e 'smtpd_sasl_auth_enable = yes'
postconf -e 'broken_sasl_auth_clients = yes'
postconf -e 'smtpd_sasl_authenticated_header = yes'
postconf -e 'smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated,
reject_unauth_destination'
postconf -e 'smtpd_use_tls = yes'
postconf -e 'smtpd_tls_cert_file = /etc/postfix/smtpd.cert'
postconf -e 'smtpd_tls_key_file = /etc/postfix/smtpd.key'
postconf -e 'transport_maps = proxy:mysql:/etc/postfix/mysql-virtual_transports.cf'
postconf -e 'virtual_create_maildirsize = yes'
postconf -e 'virtual_maildir_extended = yes'
postconf -e 'virtual_mailbox_limit_maps = proxy:mysql:/etc/postfix/mysql-
virtual_mailbox_limit_maps.cf'
postconf -e 'virtual_mailbox_limit_override = yes'
postconf -e 'virtual_maildir_limit_message = "The user you are trying to reach is over quota."'
postconf -e 'virtual_overquota_bounce = yes'
postconf -e 'proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps
$virtual_alias_domains $virtual_mailbox_maps $virtual_mailbox_domains $relay_recipient_maps
$relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps $relocated_maps
$transport_maps $mynetworks $virtual_mailbox_limit_maps'

A fterwards we c reate the SSL c ertific ate that is needed for TLS:

cd /etc/postfix
openssl req -new -outform PEM -out smtpd.cert -newkey rsa:2048 -nodes -keyout smtpd.key -keyform
PEM -days 365 -x509

Country Name (2 letter code) [AU]: <-- Enter y our Countr y N ame (e.g., "DE").
State or Province Name (full name) [Some-State]: <-- Enter y our State or Pr ov i nc e N ame.
Locality Name (eg, city) []: <-- Enter y our Ci ty .
Organization Name (eg, company) [Internet Widgits Pty Ltd]: <-- Enter y our Or gani zati on N ame (e.g., the
name of y our c ompany ).
Organizational Unit Name (eg, section) []: <-- Enter y our Or gani zati onal U ni t N ame (e.g. "IT Depar tment").
Common Name (eg, YOUR name) []: <-- Enter the Ful l y Qual i f i ed Domai n N ame of the sy stem (e.g.
"ser v er 1 .ex ampl e.c om").
Email Address []: <-- Enter y our Emai l A ddr ess.

T hen c hange the permis s ions of the smtpd.key:

chmod o= /etc/postfix/smtpd.key

Firs t run

mkdir -p /var/spool/postfix/var/run/saslauthd

T hen edit /etc/default/saslauthd. Set START to yes and c hange the line OPTIONS="-c -m /var/run
/saslauthd" to OPTIONS="-c -m /var/spool/postfix/var/run/saslauthd -r":

9 of 16 11/30/09 12:04
Virtual Users And Domains With Postfix, Courier, ... http://www.howtoforge.com/virtual-users-domains-...

vi /etc/default/saslauthd

#
# Settings for saslauthd daemon
# Please read /usr/share/doc/sasl2-bin/README.Debian fo
#

# Should saslauthd run automatically on startup? (defau


START=yes

# Description of this saslauthd instance. Recommended.


# (suggestion: SASL Authentication Daemon)
DESC="SASL Authentication Daemon"

# Short name of this saslauthd instance. Strongly recom


# (suggestion: saslauthd)
NAME="saslauthd"
T hen c reate the file /etc/pam.d/smtp. I t s hould c ontain only the following two lines (go s ure to fill in
your c orrec t databas e details ):

vi /etc/pam.d/smtp

auth required pam_mysql.so user=mail_admin passwd=


account sufficient pam_mysql.so user=mail_admin passwd=

N ext c reate the file /etc/postfix/sasl/smtpd.conf. I t s hould look like this :

vi /etc/postfix/sasl/smtpd.conf

10 of 16 11/30/09 12:04
Virtual Users And Domains With Postfix, Courier, ... http://www.howtoforge.com/virtual-users-domains-...

pwcheck_method: saslauthd
mech_list: plain login
allow_plaintext: true
auxprop_plugin: mysql
sql_hostnames: 127.0.0.1
sql_user: mail_admin
sql_passwd: mail_admin_password
sql_database: mail
sql_select: select password from users where email = '%

N ext add the postfix us er to the sasl group (this makes s ure that P os tfix has the permis s ion to
ac c es s s as lauthd):

adduser postfix sasl

T hen res tart P os tfix and Sas lauthd:

/etc/init.d/postfix restart
/etc/init.d/saslauthd restart

N ow we have to tell C ourier that it s hould authentic ate agains t our M ySQ L databas e. Firs t, edit
/etc/courier/authdaemonrc and c hange the value of authmodulelist s o that it reads :

vi /etc/courier/authdaemonrc

[...]
authmodulelist="authmysql"
[...]

T hen make a bac kup of /etc/courier/authmysqlrc and empty the old file:

11 of 16 11/30/09 12:04
Virtual Users And Domains With Postfix, Courier, ... http://www.howtoforge.com/virtual-users-domains-...

cp /etc/courier/authmysqlrc /etc/courier/authmysqlrc_orig
cat /dev/null > /etc/courier/authmysqlrc

T hen open /etc/courier/authmysqlrc and put the following lines into it:

vi /etc/courier/authmysqlrc

MYSQL_SERVER localhost
MYSQL_USERNAME mail_admin
MYSQL_PASSWORD mail_admin_password
MYSQL_PORT 0
MYSQL_DATABASE mail
MYSQL_USER_TABLE users
MYSQL_CRYPT_PWFIELD password
#MYSQL_CLEAR_PWFIELD password
MYSQL_UID_FIELD 5000
MYSQL_GID_FIELD 5000
MYSQL_LOGIN_FIELD email
MYSQL_HOME_FIELD "/home/vmail"
MYSQL_MAILDIR_FIELD CONCAT(SUBSTRING_INDEX(email,'@',-1
#MYSQL_NAME_FIELD
MYSQL_QUOTA_FIELD quota
T hen res tart C ourier:

/etc/init.d/courier-authdaemon restart
/etc/init.d/courier-imap restart
/etc/init.d/courier-imap-ssl restart
/etc/init.d/courier-pop restart
/etc/init.d/courier-pop-ssl restart

By running

telnet localhost pop3

you c an s ee if your P O P 3 s erver is working c orrec tly. I t s hould give bac k +OK Hello there. (T ype quit
to get bac k to the L inux s hell.)

root@server1:/etc/postfix# telnet localhost pop3


Trying 127.0.0.1...
Connected to localhost.localdomain.
Escape character is '^]'.
+OK Hello there.
quit
+OK Better luck next time.
Connection closed by foreign host.
root@server1:/etc/postfix#

N ow we s hould open /etc/aliases. M ake s ure that postmaster points to root and root to your own
us ername or your email addres s , e.g. like this :

12 of 16 11/30/09 12:04
Virtual Users And Domains With Postfix, Courier, ... http://www.howtoforge.com/virtual-users-domains-...

vi /etc/aliases

[...]
postmaster: root
root: postmaster@yourdomain.tld
[...]

or like this (if administrator is your own us ername):

[...]
postmaster: root
root: administrator
[...]

Whenever you modify /etc/aliases, you mus t run

newaliases

afterwards and res tart P os tfix:

/etc/init.d/postfix restart

8 .0 4 L T S) 8 .0 4 L T S) - P age 3

13 of 16 11/30/09 12:04
Virtual Users And Domains With Postfix, Courier, ... http://www.howtoforge.com/virtual-users-domains-...

T his page is lic ens ed under a C reative C ommons L ic ens e.

add c omment | view as pdf | print: this | all page(s ) |

V irtual U s ers A nd D omains With P os tfix, C ourier, M ySQ L A nd SquirrelM ail (M andriva 2 0 0 8 .1 )
V irtual U s ers A nd D omains With P os tfix, C ourier A nd M ySQ L (C entO S 5 .1 )
V irtual U s ers A nd D omains With P os tfix, C ourier A nd M ySQ L (U buntu 7 .1 0 )
V irtual U s ers A nd D omains With P os tfix, C ourier A nd M ySQ L (Fedora 8 )

Pleas e do not us e the comment function to as k for help! I f you need help, pleas e us e our forum.
Comments will be publis hed after adminis trator approval.

Ubuntu 8.04 Postfix w/ Courier , SQL, and Squirrelmail


Submitted by Middleman (not registered) on Tue, 2009-11-17 11:34.

Thanks for the guide, however i am having some trouble.

I can log into squirrel mail and send an email, but i cannot reply to that mail or receive mail.

I get mail for mail.domain.com loops back to myself

reply | view as pdf

[solved] SA SL authentication failure: cannot connect to sasl...


Submitted by Fred (not registered) on Wed, 2009-10-28 09:48.

Hello,

Thank you for this great tutoriaL.My mail server is almost running well.

I got a problem with the following error :

SASL authentication failure: cannot connect to saslauthd server: permission denied

I finally solved it thanks to this post :


http://ubuntuforums.org/showthread.php?t=196593

The solution is :

# chmod a+x /var/spool/postfix/var


# chmod a+x /var/spool/postfix/var/run
# chgrp root /var/spool/postfix/var/run

reply | view as pdf

Thanks for the tutorial,


Submitted by nicholas (not registered) on Sat, 2009-07-11 03:51.

14 of 16 11/30/09 12:04
Virtual Users And Domains With Postfix, Courier, ... http://www.howtoforge.com/virtual-users-domains-...

Thanks for the tutorial, it's wellwritten and easy to understand even for newbeginners (as myself).

I've only encountered one problem. Say that the mail-account password is "password".
Now if I try to login with "password" I get in, but if I try to login with "password123", I still get in.
It doesn't matter what I type as long as it starts with "password".

Does anyone know how to fix this?

reply | view as pdf

Re: Thanks for the tutorial,


Submitted by Nicholas (not registered) on Mon, 2009-08-03 03:33.

Fixed it, and will post it here incase anyone else wants to know:

Seems like it's MySQL's ENCRYPT that makes the password so "flexible".
I changed to MD5 and it now works like a charm :)

reply | view as pdf

Sponsored Links: Unified Communications: Thoughts, Strategies and Predictions


Join the discussion.
www.seamlessenterprise.com

IP Convergence
Integrate your wireless and wireline networks.
Learn how from the experts at Sprint.
www.seamlessenterprise.com

Wireless & Wireline Integration


Thoughts, strategies and solutions: join the discussion
www.seamlessenterprise.com

Unified Communications 2009


Join the Discussion. Now.
www.seamlessenterprise.com

Red Hat Virtual Experience - a free virtual event. Dec. 9th

15 of 16 11/30/09 12:04
Virtual Users And Domains With Postfix, Courier, ... http://www.howtoforge.com/virtual-users-domains-...

Howtos | Mini-Howtos | Forums | News | Search | Contribute | Subscription


Site Map/RSS Feeds | Advertise | Contact | Disclaimer | Imprint

Copyright © 2009 HowtoForge - Linux Howtos and Tutorials


All Rights Reserved.

16 of 16 11/30/09 12:04

You might also like