Web Hosting Forum | Lunarpages

Author Topic: Simple mail server setup on CentOS 4  (Read 30281 times)

Offline perestrelka

  • Master Jedi
  • *****
  • Posts: 1397
Simple mail server setup on CentOS 4
« on: August 26, 2006, 11:15:35 AM »
Please note all command in this tutorial should be run as root.

We will install Postfix and Dovecot (Dovecot will be our POP3/IMAP server):

Code: [Select]
yum install cyrus-sasl cyrus-sasl-devel cyrus-sasl-gssapi cyrus-sasl-md5
yum install cyrus-sasl-plain postfix dovecot

Next we configure SMTP-AUTH and TLS:

Code: [Select]
postconf -e 'smtpd_sasl_local_domain ='
postconf -e 'smtpd_sasl_auth_enable = yes'
postconf -e 'smtpd_sasl_security_options = noanonymous'
postconf -e 'broken_sasl_auth_clients = yes'
postconf -e 'smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination'
postconf -e 'inet_interfaces = all'

We must edit /usr/lib/sasl2/smtpd.conf so that Postfix allows PLAIN and LOGIN logins. It should look like this:

Code: [Select]
nano -w /usr/lib/sasl2/smtpd.conf
Quote
pwcheck_method: saslauthd
mech_list: plain login

Next we generate a self signed SSL certificate for secure connections to the SMTP server:

Code: [Select]
mkdir /etc/postfix/ssl
cd /etc/postfix/ssl/
openssl genrsa -des3 -rand /etc/hosts -out smtpd.key 1024
chmod 600 smtpd.key
openssl req -new -key smtpd.key -out smtpd.csr
openssl x509 -req -days 3650 -in smtpd.csr -signkey smtpd.key -out smtpd.crt
openssl rsa -in smtpd.key -out smtpd.key.unencrypted
mv -f smtpd.key.unencrypted smtpd.key
openssl req -new -x509 -extensions v3_ca -keyout cakey.pem -out cacert.pem -days 3650

Now we are ready to configure our Postfix:

Code: [Select]
postconf -e 'smtpd_tls_auth_only = no'
postconf -e 'smtp_use_tls = yes'
postconf -e 'smtpd_use_tls = yes'
postconf -e 'smtp_tls_note_starttls_offer = yes'
postconf -e 'smtpd_tls_key_file = /etc/postfix/ssl/smtpd.key'
postconf -e 'smtpd_tls_cert_file = /etc/postfix/ssl/smtpd.crt'
postconf -e 'smtpd_tls_CAfile = /etc/postfix/ssl/cacert.pem'
postconf -e 'smtpd_tls_loglevel = 1'
postconf -e 'smtpd_tls_received_header = yes'
postconf -e 'smtpd_tls_session_cache_timeout = 3600s'
postconf -e 'tls_random_source = dev:/dev/urandom'

After these configuration steps you should now have a /etc/postfix/main.cf that looks like this (I have removed all comments from it):

Code: [Select]
nano -w /etc/postfix/main.cf
Quote
queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix

mail_owner = postfix

myhostname = server.domain.name

mydomain = domain.name

myorigin = $myhostname

inet_interfaces = all
mydestination = $myhostname, $mydomain, localhost.$mydomain, localhost

local_recipient_maps = unix:passwd.byname $alias_maps

unknown_local_recipient_reject_code = 550


relay_domains = $mydestination

alias_maps = hash:/etc/aliases

alias_database = hash:/etc/aliases

mail_spool_directory = /var/spool/mail

debug_peer_level = 2
debugger_command =
    PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
    xxgdb $daemon_directory/$process_name $process_id & sleep 5

sendmail_path = /usr/sbin/sendmail.postfix
newaliases_path = /usr/bin/newaliases.postfix
mailq_path = /usr/bin/mailq.postfix

setgid_group = postdrop

html_directory = no

manpage_directory = /usr/share/man

smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination
smtpd_tls_auth_only = no
smtp_use_tls = yes
smtpd_use_tls = yes
smtp_tls_note_starttls_offer = yes
smtpd_tls_key_file = /etc/postfix/ssl/smtpd.key
smtpd_tls_cert_file = /etc/postfix/ssl/smtpd.crt
smtpd_tls_CAfile = /etc/postfix/ssl/cacert.pem
smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
tls_random_source = dev:/dev/urandom

message_size_limit = 20971520
mailbox_size_limit = 104857600

Here are the parameters that need changing from the default:

myhostname = server.domain.name

mydomain = domain.name

myorigin = $mydomain

mydestination = $myhostname, $mydomain, localhost.$mydomain, localhost

local_recipient_maps = unix:passwd.byname $alias_maps

unknown_local_recipient_reject_code = 550

relay_domains = $mydestination

mail_spool_directory = /var/spool/mail


Also in the bottom of the /etc/postfix/main.cf file, you can add a setting for max mail box size and max attachment size. I will assume 20mb max attachment and 100mb max mailbox size. Here is what to add for that:

message_size_limit = 20971520
mailbox_size_limit = 104857600

By default, CentOS' Dovecot daemon provides only IMAP and IMAPs services. Because we also want POP3 and POP3s we must configure Dovecot to do so. We edit /etc/dovecot.conf and put the line protocols = imap imaps pop3 pop3s into it:

Code: [Select]
nano -w /etc/dovecot.conf
Quote
[...]
# Base directory where to store runtime data.
#base_dir = /var/run/dovecot/

# Protocols we want to be serving:
#  imap imaps pop3 pop3s
protocols = imap imaps pop3 pop3s

# IP or host address where to listen in for connections. It's not currently
# possible to specify multiple addresses. "*" listens in all IPv4 interfaces.
[...]

Now start Postfix, Saslauthd, and Dovecot:

Code: [Select]
chkconfig --levels 235 sendmail off
chkconfig --levels 235 postfix on
chkconfig --levels 235 saslauthd on
chkconfig --levels 235 dovecot on
/etc/init.d/sendmail stop
/etc/init.d/postfix start
/etc/init.d/saslauthd start
/etc/init.d/dovecot start

To see if SMTP-AUTH and TLS work properly now run the following command:

Code: [Select]
telnet server.domain.name 25
After you have established the connection to your Postfix mail server type:

Code: [Select]
ehlo server
If you see the following lines and a mail server greeting:

250-STARTTLS

and

250-AUTH

everything is fine.  Otherwise, check if Postfix is listening on the port 25 using netstat and firewall is not blocking incoming SMTP connections.

In this setup, all users who have accounts on the server with a password can send and receive e-mail.  Point the MX entry of your domain to the server and your personal mail server is ready to go.
Kind Regards,
Vlad Artamonov

Offline mikereynolds

  • Pong! (the videogame) Master
  • *****
  • Posts: 22
Re: Simple mail server setup on CentOS 4
« Reply #1 on: February 19, 2007, 11:40:12 PM »
Hello,

I ran into an issue using the postfix supplied in the centosplus repository when using mysql5.

I received the following error;
Code: [Select]
/usr/sbin/postconf: /usr/lib/mysql/libmysqlclient.so.14: no version information available (required by /usr/sbin/postconf)

The solution is pretty simple. Install postgresql-devel;
Code: [Select]
yum install postgresql-devel

Uninstall the existing postfix if you have installed it already;
Code: [Select]
yum remove postfix

Download the postfix src rpm here from a mirror. For example;
Code: [Select]
wget http://mirror.stanford.edu/yum/pub/centos/4.4/centosplus/i386/SRPMS/postfix-2.2.10-1.RHEL4.2.mysql_pgsql.c4.src.rpm

Rebuild the rpm from the source you downloaded;
Code: [Select]
rpmbuild --rebuild postfix-2.2.10-1.RHEL4.2.mysql_pgsql.c4.src.rpm

Edit /etc/yum.conf to disable gpg checks temporarily (change the 1 to a 0)

Install the rpm we just built;
Code: [Select]
yum install /usr/src/redhat/RPMS/i386/postfix-2.2.10-1.RHEL4.2.mysql_pgsql.c4.i386.rpm

Edit /etc/yum.conf and re-enable gpg checks (change the 0 back to 1)

You can now continue as normal from the "Next we configure SMTP-AUTH and TLS:" step.

Hope this saves someone a headache.
« Last Edit: February 20, 2007, 01:19:28 AM by mikereynolds »

Lupine1647

  • Guest
Re: Simple mail server setup on CentOS 4
« Reply #2 on: February 20, 2007, 04:52:19 PM »
Now, I'm going to take this off topic just a little but not entirely since it deals with e-mail. I looked all over for a comparison between Courier + Exim and Postfix + Dovecot for e-mail. Any reason to use one setup more than the other?

Right now I setup Exim + Courier on my server utilizing a mysql server (seems to make my life easier for some reason) and has been working very well.

Other than that little Q, great tutorial :)

Offline perestrelka

  • Master Jedi
  • *****
  • Posts: 1397
Re: Simple mail server setup on CentOS 4
« Reply #3 on: March 27, 2007, 10:44:05 PM »
Hi RyanJ,

Maybe this reply a bit delayed ;).

We didn't offer a mail system setup with mysql because it is a bit complex. If a user can do such setup using instructions he found over the Internet, apparently he does not need this tutorial. However, please feel free to share your experience with using mysql to keep info about email users.

As for Exim+Courier-imap or Postfix+Dovecot comparison, the both works fine. Postfix and Dovecot were chosen because they are included in CentOS install by default.
Kind Regards,
Vlad Artamonov

Offline amadou

  • Newbie
  • *
  • Posts: 1
Re: Simple mail server setup on CentOS 4
« Reply #4 on: July 28, 2007, 03:03:36 PM »
Hello and thank you for this helpfull tutorial.
I would like to use postfix for vhost.
Can someone help on how to configure postfix for virtual mails for different domains where mails are only defined for their specific domains, i.e david@domain1.com is only defined for domain1 (david@domain2.com would be a different user).
Also how do I fixe the return email to say david@domain1.com instead of david@server.domain1.com

Thank you again for your supports

Offline perestrelka

  • Master Jedi
  • *****
  • Posts: 1397
Re: Simple mail server setup on CentOS 4
« Reply #5 on: July 28, 2007, 07:24:22 PM »
I would like to use postfix for vhost.
Can someone help on how to configure postfix for virtual mails for different domains where mails are only defined for their specific domains, i.e david@domain1.com is only defined for domain1 (david@domain2.com would be a different user).

Please use the following guide to setup Postfix with virtual users on CentOS:

http://howtoforge.com/virtual_users_postfix_courier_mailscanner_clamav_centos

Also how do I fixe the return email to say david@domain1.com instead of david@server.domain1.com


This depends only on the sender email address which is set in the email client settings and does not get setup through the server unless sender address rewrite is forced in the server which requires special settings which are off by default.

I hope this helps.
Kind Regards,
Vlad Artamonov

Offline rgoldman84

  • Newbie
  • *
  • Posts: 2
Re: Simple mail server setup on CentOS 4
« Reply #6 on: November 24, 2010, 08:12:16 PM »
This is an old thread but most of this will still work today.

I have a few questions regarding the general installation of dovecot. If anyone has done this on CentOS 4.8 or can provide some info that would be great. (Apologies if this isn't the right forum! It looks like a good place to post  :D)

How will dovecot installation break or interfere with existing popa3d service? Does that need to be removed first, before installing dovecot? What if the server fails and must be rebooted, does the dovecot installation install startup scripts so the services will be started automatically?

Server version: CentOS release 4.8 (Final)

Thanks and Best Regards
« Last Edit: November 24, 2010, 08:16:13 PM by rgoldman84 »

Offline perestrelka

  • Master Jedi
  • *****
  • Posts: 1397
Re: Simple mail server setup on CentOS 4
« Reply #7 on: November 26, 2010, 07:51:13 AM »
This is an old thread but most of this will still work today.

I have a few questions regarding the general installation of dovecot. If anyone has done this on CentOS 4.8 or can provide some info that would be great. (Apologies if this isn't the right forum! It looks like a good place to post  :D)

How will dovecot installation break or interfere with existing popa3d service? Does that need to be removed first, before installing dovecot? What if the server fails and must be rebooted, does the dovecot installation install startup scripts so the services will be started automatically?

Server version: CentOS release 4.8 (Final)

Thanks and Best Regards

If popa3d uses maildir storage format, Dovecot can just replace popa3d transparently. It will be required to stop popa3d  at least before starting dovecot as they use the same ports. After it is confirmed Dovecot runs fine, you can remove popa3d.

It is advisable to check that Dovecot is set to start automatically when you switch to it. The command "chkconfig --list dovecot" will help you with that. If it shows "on" for 3, 4 and 5 levels, Dovecot is configured to be started on boot.
Kind Regards,
Vlad Artamonov

Offline rgoldman84

  • Newbie
  • *
  • Posts: 2
Re: Simple mail server setup on CentOS 4
« Reply #8 on: November 27, 2010, 03:12:37 PM »
Ok, I successfully moved my mail data over and installed postfix/dovecot.

One can edit /etc/xinetd.d/popa3d* and change "disable = no" to "disable = yes". Then, restart xinetd without popa3d services: "service xinetd restart". (I think I actually removed it first then ran "killall -HUP xinetd")

Next install dovecot. After that is working, it is probably safe to remove popa3d: "yum remove popa3d"

Make sure dovecot is set to run at startup: "chkconfig --levels 345 dovecot on"

Same for postfix, I had to add that one using: "chkconfig --add postfix"

TIP: disregard the following info unless you wish to use maildir format. If you wish to change from mbox to maildir format you can use the convert-and-create script at http://www.qmail.org/convert-and-create. By default the script will copy user mail from /var/spool/mail/user to the user's home directory (usually /home/user/Maildir). If you change to maildir format you must tell postfix in main.cf: "home_mailbox = Maildir/". To be safe one might configure dovecot.conf also: "default_mail_env = maildir:%h/Maildir"

Offline perestrelka

  • Master Jedi
  • *****
  • Posts: 1397
Re: Simple mail server setup on CentOS 4
« Reply #9 on: December 11, 2010, 07:43:18 AM »
Ok, I successfully moved my mail data over and installed postfix/dovecot.

One can edit /etc/xinetd.d/popa3d* and change "disable = no" to "disable = yes". Then, restart xinetd without popa3d services: "service xinetd restart". (I think I actually removed it first then ran "killall -HUP xinetd")

Next install dovecot. After that is working, it is probably safe to remove popa3d: "yum remove popa3d"

Make sure dovecot is set to run at startup: "chkconfig --levels 345 dovecot on"

Same for postfix, I had to add that one using: "chkconfig --add postfix"

TIP: disregard the following info unless you wish to use maildir format. If you wish to change from mbox to maildir format you can use the convert-and-create script at http://www.qmail.org/convert-and-create. By default the script will copy user mail from /var/spool/mail/user to the user's home directory (usually /home/user/Maildir). If you change to maildir format you must tell postfix in main.cf: "home_mailbox = Maildir/". To be safe one might configure dovecot.conf also: "default_mail_env = maildir:%h/Maildir"

Sorry for the late message. My congratulations on successful migration. Thanks for adding more valuable info to this post as well.
Kind Regards,
Vlad Artamonov

Offline donnieX

  • Newbie
  • *
  • Posts: 1
Re: Simple mail server setup on CentOS 4
« Reply #10 on: June 24, 2011, 04:30:08 AM »
Hello and thank you for this helpfull tutorial.
I would like to use postfix .
Can someone help on how can i recieve emails inbox of my emaildomaine , i can send but i can't recieve  any message...
thank you in advance...

 

Share |