Configuring basic SMTP, IMAP, POP and HTTP access for complete email on a single server

From Notes_Wiki

Home > CentOS > CentOS 6.x > Email server configuration > Configuring basic SMTP, IMAP, POP and HTTP access for complete email on a single server

Cloud Account creation and DNS entries

  1. Create a dedicated cloud account (eg linode)
  2. Create CentOS instance with public IP
  3. Ensure that firewall for the VM allows SSH, HTTP, HTTPS, IMAP, IMAPS, SMTP, STMPS, POP3, POP3S and ICMP
  4. Register domain name through registrar eg godaddy
  5. Update DNS entries for domain, www, mail, MX record to point to public IP of the VM


Configure system

  1. Set correct timezone on system using CentOS 7.x Change system timezone
  2. Configure history using Storing date / time along with commands in history
  3. In case of public cloud VM consider adding swap by referring CentOS 7.x adding swap space using file


Configure web server

  1. yum -y install httpd mod_ssl
  2. service httpd start
  3. Edit iptables to allow incoming connections to port 80, 443
  4. service iptables restart
  5. Put test file in /var/www/html
  6. Open domain in browser to verify that website is accessible. (Wait at least 3-4 minutes after updating DNS entries to avoid getting wrong values cached in near-by DNS)
  7. chkconfig httpd on
  8. Edit /etc/httpd/conf/httpd.conf and update 'Listen 80' to 'Listen 0.0.0.0:80'

For public facing server it might make sense to get recognized SSL certificates from CA. For example refer Installing lets-encrypt SSL certificate


Create users

  1. useradd saurabh
  2. passwd saurabh

Similarly more users can be created


Setup postfix SMTP server

  1. Edit '/etc/postfix/main.cf' as follows:
    1. Set myhostname=mail.sbarjatiya.com
    2. Set mydomain=sbarjatiya.com
    3. Set myorigin=$mydomain
    4. Set inet_interfaces=all (Comment inet_interfaces=localhost)
    5. Prepend $mydomain to mydestination value (Without this only @mail.domain.com mails would get accepted. After this change @domain.com would also work)
  2. service postfix restart
  3. Edit /etc/sysconfig/network and set correct hostname.
  4. Edit /etc/hosts and correct hostname
  5. hostname mail.sbarjatiya.com
  6. Allow incoming connections to port 25 and 465

Also refer to Postfix SMTP authentication using dovecot

Increase postfix message and mailbox size limit using Troubleshooting_postfix_server_issues#Message_file_too_big_issue


Setup dovecot

  1. yum -y install dovecot
  2. Edit /etc/postfix/main.cf and set 'home_mailbox = mail/'
  3. service postfix restart
  4. Edit /etc/dovecot/conf.d/10-mail.conf and set 'mail_location = maildir:~/mail'
  5. service dovecot start
  6. Allow incoming connections to ports 110,143,993,995
  7. chkconfig dovecot on


Setup squirrelmail

  1. yum -y install wget
  2. Setup rpmfusion, repoforge and epel
  3. yum -y install squirrelmail
  4. cd /usr/share/squirrelmail/config and run './conf.pl'
    1. Set Organization Preferences -> Organization name
    2. Set Server Settings -> Domain
    3. Set Server Settings -> IMAP Settings. Use values mail.sbarjatiya.com, 993, Secure (IMAP): true, Server software: dovecot
    4. Setup mail sending using sendmail and not through SMTP
  5. Open <domain>/webmail in browser
  6. setenforce 0
  7. edit /etc/sysconfig/selinux and set SELINUX=disabled
  8. set correct timezone in PHP using following in /etc/php.ini:
    date.timezone="Asia/Kolkata"
    Refer: https://www.php.net/manual/en/timezones.php for list of all possible timezones


Note that user must login into squirrelmail interface once before he/she can receive email. This is required for creating necessary folders in home folder.


Squirrelmail change password support

  1. Download change_passwd and compatability (Version 1.3) plugins from
    http://squirrelmail.org/countdl.php?fileurl=http%3A%2F%2Fwww.squirrelmail.org%2Fplugins%2Fchange_passwd-4.0-1.2.8.tar.gz
    http://squirrelmail.org/countdl.php?fileurl=http%3A%2F%2Fwww.squirrelmail.org%2Fplugins%2Fcompatibility-1.3.tar.gz
  2. cd /usr/share/squirrelmail/plugins
  3. Extract both .tar.gz file here
  4. For change_passwd read INSTALL file and perform necessary steps
    1. cp config.php.sample config.php
    2. yum -y install gcc
    3. gcc -lcrypt -O -o chpasswd chpasswd.c
    4. chown root:apache chpasswd
    5. chmod 4750 chpasswd
  5. Go to /usr/share/squirrelmail/config
  6. Again run ./conf.pl and enable both plugins (Compatability plugin must load before change_password plugin. Edit /etc/squirrelmail/config.php by hand if that is not the case)


Troubleshooting change password support

Squirrelmail change password support requires use of md5 salted hash and does not supports sha256 or sha512. In case machine is configured to use only sha256 hash for password then the plugin will not work and will always report old password as incorrect. To resolve this use following steps:

  1. Edit /etc/libuser.conf and set 'crypt_style md5'
  2. yum -y install authconfig
  3. Edit /etc/sysconfig/authconfig and set 'PASSWDALGORITHM=md5'. The same can also be achived by running 'authconfig-tui' and enabling use of md5 for passwords.
  4. Test by going to /usr/share/squirrelmail/plugins/change_passwd folder and by running command 'sudo ./chpasswd <username> <old_password> <new_password>'. If this fails then changing through browser will also fail as the browser plugin calls this script to change password.


Migrating email server

For migrating email server setup this way refer to Migrating mail server from one machine to another



Home > CentOS > CentOS 6.x > Email server configuration > Configuring basic SMTP, IMAP, POP and HTTP access for complete email on a single server