Remove exim4 on Debian 7

Remove just exim4 package itself on Debian 7 with following command

#apt-get remove exim4

Remove exim4 with dependent packages on Debian 7 with following command

#apt-get remove --auto-remove exim4

Remove exim4 and delete configuration, data files on Debian 7 with following command

#apt-get purge exim4

Remove and delete exim4 configuration, data files, dependencies on Debian 7 with following command

#apt-get purge --auto-remove exim4

Postfix SMTP Relay Gmail Debian 7

Update Debian with current updates with Aptitude command

Install Aptitude command following aptitude update

#apt-get update -y && apt-get upgrade -y

Remove and delete exim4 configuration, data files, dependencies on Debian 7 with following command

#apt-get purge --auto-remove exim4

Make sure the postfix, libsasl2-modules and ca-certificates package is installed and up to date:

#apt-get install postfix libsasl2-modules ca-certificates mailutils

Set Postfix to start on server boot:

#update-rc.d postfix defaults

Remove postfix start on server boot

#update-rc.d postfix disable

Enable postfix start on server boot

#update-rc.d postfix enable

During Postfix installation, a pop up will appear asking for configuration.

  • For “General type of mail configuration,” choose Internet Site.
  • For System Mail name insert system hostname.
  • For any other question, choose default values.

Configuring Gmail SMTP Usernames and Passwords Authentication

Create or edit the password file:

#nano /etc/postfix/sasl_passwd

Add this line:

[smtp.gmail.com]:587 [email protected]:password

Create hash db file for Postfix by running the postmap command:

#postmap /etc/postfix/sasl_passwd

Securing Password and Hash Database Files.

The /etc/postfix/sasl_passwd and the /etc/postfix/sasl_passwd.db files created in the previous steps contain your SMTP credentials in plain text. For security reasons, change ownership and permissions to root for the two files:

#chown root:root /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
#chmod 0600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db

Next, validate certificates to avoid running into error. Run following command:

#cat /etc/ssl/certs/Thawte_Premium_Server_CA.pem | tee -a /etc/postfix/cacert.pem

On Debian 8

Thawte_Premium_Server_CA.pem not exist on Debian 8,so we have to download it manually

#cd /etc/ssl/certs
#wget https://www.thawte.com/roots/thawte_Premium_Server_CA.pem
#mv thawte_Premium_Server_CA.pem Thawte_Premium_Server_CA.pem
#cat /etc/ssl/certs/Thawte_Premium_Server_CA.pem | tee -a /etc/postfix/cacert.pem

Configuring the Relay Server on Postfix configuration /etc/postfix/main.cf file to use the external SMTP server.

#nano /etc/postfix/main.cf

Insert following gmail SMTP relay host line

relayhost = [smtp.gmail.com]:587

At the end of the file, add the following parameters to enable authentication:

#nano /etc/postfix/main.cf

Then add the following parameters on /etc/postfix/main.cf to enable authentication:

#enable SASL authentication
smtp_sasl_auth_enable = yes
# disallow methods that allow anonymous authentication.
smtp_sasl_security_options = noanonymous
# where to find sasl_passwd
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
# Enable STARTTLS encryption
smtp_use_tls = yes
# where to find CA certificates
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

Save the changes and Restart Postfix:

#service postfix restart

Send test email to test if Relay work good with mail command below

echo "This is a test." | mail -s "test message" [email protected]

Check the logs for any Postfix errors on Debian

#tail -f /var/log/mail.log

Error and Troubleshooting

Port 25 open by iptables firewall
Make sure port 25 open has been accept by iptables firewall, visit this article to Install and Set Up Iptables Firewall on Centos 6
Postfix Gmail SMTP Relay access denied

rcpt to: [email protected]
554 5.7.1 <[email protected]>: : Relay access denied

Your Google Account has been suspendedYour-Google-Account-has-been-suspended

Hi vpshelpdesk,
Google has suspended your Account, [email protected], because of a violation of our Terms of Service.

Please follow possible solution below, so far it is working for meallow-less-secure-apps-ON

Change the “allow less secure apps” setting to enable. This allows them to connect to the account again.
Insert and Verify Account recovery email and phoneVerify-Account-recovery-email-and-phone

If Gmail SMTP Relay rare to use and rare sign in sometimes the message will not deliver again. Once check tail -f /var/log/maillog, we will find error below;

May 16 14:31:43 vpsheldesk.com postfix/smtp[1096]: D738BA40BE0: to=, relay=smtp.gmail.com[74.125.138.109]:587, delay=31, delays=0.01/0.04/31/0, dsn=4.7.14, status=deferred (SASL authentication failed; server smtp.gmail.com[74.125.138.109] said: 534-5.7.14 Please log in via your web browser and?534-5.7.14 then try again.?534-5.7.14 Learn more at?534 5.7.14 https://support.google.com/mail/answer/78754 w190sm8732463ywa.39 - gsmtp)
Visit GMAIL HELP https://support.google.com/mail/answer/78754 and follow the instructions


Can’t sign in to my email app
If you’re using the wrong Gmail password on another email app, you might have these problems:

  • The app keeps asking for your username and password
  • You see an “invalid credentials” error message
  • You see a “web login required” error message

If you have these problems or can’t sign in, first check to make sure you’re using the right password.

Tip: Keep in mind that passwords are case-sensitive.
Troubleshoot sign-in problems
If you’re sure your password is right, try these tips:

  • If you’ve turned on 2-Step Verification for your account, you might need to enter an App password instead of your regular password.
  • Sign in to your account from the web version of Gmail at https://mail.google.com. Once you’re signed in, try signing in to the mail app again.
  • Visit http://www.google.com/accounts/DisplayUnlockCaptcha and sign in with your Gmail username and password. If asked, enter the letters in the distorted picture.
  • Your app might not support the latest security standards. Try changing a few settings to allow less secure apps access to your account.
  • Make sure your mail app isn’t set to check for new email too often. If your mail app check for new messages more than once every 10 minutes, the app’s access to your account could be blocked.
  • Change your password according to our tips on creating a strong password.

Set Up Postfix Local Mail Server, Dovecot, Squirrelmail On CentOS 6

This article describe how to set up and configure Postfix Mail Server with Dovecot and Squirrelmail On CentOS 6 at Local Area Network.

Set up and configure Postfix Mail Server to receive and send email on public area network (internet) with domain name ([email protected]) is very complex and difficult to set up, need much resources like static public ip address, stable server, etc.
As an alternative we can set up and configure Postfix to use Gmail as a Mail Relay, only need a Postfix Mail Server installed and a Gmail account  to configure MTA to relay outgoing mail through Gmail.

Postfix is a free open source mail transfer agent (MTA).

Dovecot is an open source IMAP and POP3 mail server for Unix/Linux systems.

SquirrelMail is a standards-based webmail package written in PHP support for the IMAP and SMTP protocols, and all pages render in pure HTML 4.0 (with no JavaScript required) for maximum compatibility across browsers.

It is important to disabled SELinux to reduce complexity in postfix configuration.
Remove default MTA sendmail first if it’s already installed

# yum remove sendmail

Add hostname entries in /etc/hosts file as shown below:

# vi /etc/hosts
127.0.0.1 localhost localhost.localdomain
::1 localhost localhost.localdomain
192.168.1.101 server.vpshelpdesk.local vpshelpdesk

Install Postfix package using the command:

# yum install postfix -y

Configuring Postfix, Edit /etc/postfix/main.cf,

# vi /etc/postfix/main.cf

find and edit the following lines:

## Line no 75 - Uncomment and set your mail server FQDN ##
myhostname = vpshelpdesk.local
## Line 83 - Uncomment and Set domain name ##
mydomain = vpshelpdesk
## Line 99 - Uncomment ##
myorigin = $mydomain
## Line 116 - Set ipv4 ##
inet_interfaces = all
## Line 119 - Change to all ##
inet_protocols = all
## Line 164 - Comment ##
#mydestination = $myhostname, localhost.$mydomain, localhost,
## Line 165 - Uncomment ##\
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
## Line 264 - Uncomment and add IP range ##
mynetworks = 192.168.1.0/24, 127.0.0.0/8
## Line 419 - Uncomment ##
home_mailbox = Maildir/

Save and exit the file. Start/restart Postfix service now:

# service postfix restart
# chkconfig postfix on

Testing Postfix mail server
First, create a test user called “SK“.

# useradd sk
# passwd sk

Access the server via Telnet and enter the commands manually shown in ## ##

# telnet localhost smtp
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 vpshelpdesk.local ESMTP Postfix
ehlo localhost ## type this command ##
250-server.vpshelpdesk.local
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
mail from:<sk> ## Type this - mail sender address##
250 2.1.0 Ok
rcpt to:<sk> ## Type this - mail receiver address ##
250 2.1.5 Ok
data ## Type this to input email message ##
354 End data with <CR><LF>.<CR><LF>
welcome to vpshelpdesk mail server ## Enter the body of the email ##.
## type dot (.) to complete message ##
250 2.0.0 Ok: queued as B822221522
quit ## type this to quit from mail ##
221 2.0.0 Bye
Connection closed by foreign host.

Now navigate to the user “sk“ mail directory and check for the new mail:

# ls /home/sk/Maildir/new/
Sample output:

1390215275.Vfd00Ie04f8M357080.vpshelpdesk.local
A new mail is received to the user “sk“. To read the mail, enter the following command:
# cat /home/sk/Maildir/new/1390215275.Vfd00Ie04f8M357080.mail.local
Sample output:
Return-Path: <[email protected]>
X-Original-To: sk
Delivered-To: [email protected]
Received: from localhost (localhost [IPv6:::1])
by mail.local (Postfix) with ESMTP id B822221522
for <sk>; Mon, 20 Jan 2014 16:23:54 +0530 (IST)
Message-Id: <[email protected]>
Date: Mon, 20 Jan 2014 16:23:54 +0530 (IST)
From: [email protected]
To: undisclosed-recipients:;
welcome to vpshelpdesk mail server

Installing Dovecot
Dovecot is an open source IMAP and POP3 mail server for Unix/Linux systems. To install:

# yum install dovecot

Configuring Dovecot
Edit the file /etc/dovecot/dovecot.conf file,

#vi /etc/dovecot/dovecot.conf

Uncomment the following line:

## Line 20 - umcomment ##
protocols = imap pop3 lmtp

Edit file /etc/dovecot/conf.d/10-mail.conf file

#vi /etc/dovecot/conf.d/10-mail.conf

Make the changes as shown below:

## Line 24 - uncomment ##
mail_location = maildir:~/Maildir

Edit /etc/dovecot/conf.d/10-auth.conf

#vi /etc/dovecot/conf.d/10-auth.conf

And make the changes as shown below:

## line 9 - uncomment##
disable_plaintext_auth = yes
## Line 97 - Add a letter "login" ##
auth_mechanisms = plain login

Edit file /etc/dovecot/conf.d/10-master.conf,

# vi /etc/dovecot/conf.d/10-master.conf

Make changes as shown below:

## Line 83, 84 - Uncomment and add "postfix"
#mode = 0600
user = postfix
group = postfix

Start Dovecot service:

# service dovecot start
# chkconfig dovecot on

Testing Dovecot
It’s time to test Dovecot configuration. Enter the following command in Terminal:

#telnet localhost pop3
Enter the commands manually marked in red color:
Trying ::1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.
user sk ## log in as user sk ##
+OK
pass centos ## input user password ##
+OK Logged in.
retr 1
+OK 439 octets
Return-Path: <[email protected]>
X-Original-To: sk
Delivered-To: [email protected]
Received: from localhost (localhost [IPv6:::1])
by server.vpshelpdesk.local (Postfix) with ESMTP id B822221522
for <sk>; Mon, 20 Jan 2014 16:23:54 +0530 (IST)
Message-Id: <[email protected]>
Date: Mon, 20 Jan 2014 16:23:54 +0530 (IST)
From: [email protected]
To: undisclosed-recipients:;
welcome to vpshelpdesk mail server
.
quit
+OK Logging out.
Connection closed by foreign host.

Good Dovecot is working!

Installing Squirrelmail
Make sure that you’ve installed and enabled EPEL repository. Now install Squirrelmail using the following command:

#yum install squirrelmail

Configuring Squirrelmail
Navigate to /usr/share/squirrelmail/config/ directory and run the command conf.pl:

# cd /usr/share/squirrelmail/config/
# ./conf.pl

The following wizard will open. Enter choice “1” to set your organization details:

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Main Menu --
1. Organization Preferences
2. Server Settings
3. Folder Defaults
4. General Options
5. Themes
6. Address Books
7. Message of the Day (MOTD)
8. Plugins
9. Database
10. Languages
D. Set pre-defined settings for specific IMAP servers
C Turn color off
S Save data
Q Quit
Command >> 1
The following wizard will open. Enter “1” again to modify your organization details:
SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Organization Preferences
1. Organization Name : SquirrelMail
2. Organization Logo : ../images/sm_logo.png
3. Org. Logo Width/Height : (308/111)
4. Organization Title : SquirrelMail $version
5. Signout Page :
6. Top Frame : _top
7. Provider link : http://squirrelmail.org/
8. Provider name : SquirrelMail
R Return to Main Menu
C Turn color off
S Save data
Q Quit
Command >> 1
Set your Organization name and press Enter:
SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Organization Preferences
1. Organization Name : vpshelpdesk
2. Organization Logo : ../images/sm_logo.png
3. Org. Logo Width/Height : (308/111)
4. Organization Title : SquirrelMail $version
5. Signout Page :
6. Top Frame : _top
7. Provider link : http://squirrelmail.org/
8. Provider name : vpshelpdesk Mail
R Return to Main Menu
C Turn color off
S Save data
Q Quit
Command >> s
Now enter “2” to setup mail Server settings such as domain name and mail agent etc.:

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Main Menu --
1. Organization Preferences
2. Server Settings
3. Folder Defaults
4. General Options
5. Themes
6. Address Books
7. Message of the Day (MOTD)
8. Plugins
9. Database
10. Languages
D. Set pre-defined settings for specific IMAP servers
C Turn color off
S Save data
Q Quit
Command >> 2
Enter “1”, Enter your mail domain (ex. vpshelpdesk. local) and press Enter key.

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Server Settings
General
-------
1. Domain : localhost
2. Invert Time : false
3. Sendmail or SMTP : Sendmail
A. Update IMAP Settings : localhost:143 (uw)
B. Change Sendmail Config : /usr/sbin/sendmail
R Return to Main Menu
C Turn color off
S Save data
Q Quit
Command >> 1
The domain name is the suffix at the end of all email addresses. If
for example, your email address is [email protected], then your domain
would be example.com.
[localhost]: unixmen.local
Enter “3” and change from sendmail to Postfix MTA (i.e. SMTP):

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Server Settings
General
-------
1. Domain : unixmen.local
2. Invert Time : false
3. Sendmail or SMTP : Sendmail
A. Update IMAP Settings : localhost:143 (uw)
B. Change Sendmail Config : /usr/sbin/sendmail
R Return to Main Menu
C Turn color off
S Save data
Q Quit
Command >> 3
Enter “2” to switch from sendmail MTA to postfix.

You now need to choose the method that you will use for sending
messages in SquirrelMail. You can either connect to an SMTP server
or use sendmail directly.
1. Sendmail
2. SMTP
Your choice [1/2] [1]: 2
Now enter “S” followed by “Q” to save and exit Squirrelmail configuration.

Create a squirrelmail vhost in apache config file:

#vi /etc/httpd/conf/httpd.conf
Add the following lines at the end:
Alias /webmail /usr/share/squirrelmail
<Directory /usr/share/squirrelmail>
Options Indexes FollowSymLinks
RewriteEngine On
AllowOverride All
DirectoryIndex index.php
Order allow,deny
Allow from all
</Directory>

Restart the Apache service:

#service httpd restart

Create users
Create some users for testing. In my case i create two users called “senthil“ and “kumar“ respectively.

# useradd senthil
# useradd kumar
# passwd senthil
# passwd kumar

Access Webmail
Now navigate to http://ip-address/webmail or http://domain-name/webmail from your browser. The following screen should appear. Enter the username and password of the user.

Now you’ll be able to access the user senthil mail box. Let us compose a test mail from user “senthil“ to user “kumar“. Click on the Compose link on the top. Enter the recipient mail id (ex. [email protected]), subject and body of the mail and click Send.

Now log out from user “senthil“ and log in to user “kumar“ mail and check for any new mail.

Hurrah! We have got a new mail from [email protected] mail id. To read the mail, click on it. You’ll now be able to read, reply, delete or compose a new mail.

That’s it for now. We’ve successfully configured a local mail server that will serve in/out mails within a local area network. But i want to configure a public mail server to send and receive mails to outside of our LAN, what should i do? That’s not that difficult either.

You should configure mail server with a public IP and request your ISP to put the MX record of your mail server into their DNS server and you’re done! Everything will be same as i described above.

Setup DNS server and add the Mail server MX records in the forward and reverse zone files. To install and configure DNS server, navigate to this link. And you’ll need to contact your ISP to point your external static IP to your mail domain.

This article taken from http://www.unixmen.com/install-postfix-mail-server-with-dovecot-and-squirrelmail-on-centos-6-4/

Set up Postfix Gmail SMTP Relay on CentOS 6

This article describe how to Set up and Configure Postfix Gmail SMTP Relay on CentOS 6, we will set up Gmail as a Mail Relay, a Gmail account must ready to configure MTA to relay outgoing mail through Gmail.
Postfix is an MTA (Mail Transfer Agent), an application used to send and receive email.
GMail is a free web-based email service by Google with reliability and robust infrastructure who provides a simple sending email from the command line with smtp.gmail.com:587.

We Assume a website have contact form php page for visitor to send message. Postifx Mail Transfer Agent will deliver the message to recipient but guarantee the message will mark as spam. But if Postifx configure to use GMail as SMTP Relay, the message will send by Gmail account which already set up and configure on Postifx, so far the message will store at inbox not spam.

Install Postfix, make sure SASL authentication framework, and mailx also installed.
First Remove default MTA sendmail first if it’s already installed, make sure postfix as default MTA

#yum remove sendmail
#yum install postfix cyrus-sasl-plain mailx -y

Postfix will need to be start before the SASL framework will be detected.

#service postfix start

If error occurred postfix failed to start

Starting postfix:                                          [FAILED]
#tail -f /var/log/maillog
postfix[1070]:fatal:config variable inet_interfaces:host not found:localhost

Change the inet_interfaces setting in /etc/postfix/main.cf from:

inet_interfaces = localhost inet_interfaces = 127.0.0.1

Postfix should also be set to start on boot.

#chkconfig postfix on

Check that Postfix configured with SSL support (ie. ldd should return at least one line starting with libssl):

#whereis -b postfix
postfix: /usr/sbin/postfix /etc/postfix /usr/libexec/postfix
#ldd /usr/sbin/postfix
libssl.so.6 => /lib/libssl.so.6 (0x00111000)

Find your server’s CA root certificate bundle path, which is typically distributed with openssl. The bundle file is used by Postfix to verify Gmail’s SSL certificate (signed by Thawte).

#locate ca-bundle.crt
/etc/ssl/certs/ca-bundle.crt

Then edit /etc/postfix/main.cf, simply add/paste the following lines to the end of the file.

#vi /etc/postfix/main.cf
myhostname = hostname.example.com
relayhost = [smtp.gmail.com]:587
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_tls_CAfile = /etc/ssl/certs/ca-bundle.crt
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous

The myhostname is optional. If hostname is not specified, Postfix will use the fully-qualified domain name of the server.

Configure Postfix SASL Credentials
The Gmail credentials must now be added for authentication. Create a /etc/postfix/sasl_passwd file and add following line:

#vi /etc/postfix/sasl_passwd
[smtp.gmail.com]:587 username:password

The username and password values must be replaced with valid Gmail credentials.
A Postfix lookup table must now be generated from the sasl_passwd text file by running the following command.

#postmap /etc/postfix/sasl_passwd

Access to the sasl_passwd files should be restricted.

#chown root:postfix /etc/postfix/sasl_passwd*
#chmod 640 /etc/postfix/sasl_passwd*

Lastly, reload the Postfix configuration.

#service postfix restart

Test the Relay
Use the mail command to test the relay.

echo "This is a test." | mail -s "test message" [email protected]

The destination address should receive the test message.
Troubleshoot Delivery Issues
The maillog can be reviewed if the test message is not successfully delivered. Open another shell and run tail while performing another test.

tail -f /var/log/maillog

If there are not enough details in the maillog to determine the problem, then the debug level can be increased by adding the following lines to the /etc/postfix/main.cf.

debug_peer_list=smtp.gmail.com
debug_peer_level=3

The Postfix configuration must be reloaded after updating the main.cf file.

#service postfix restart

Remember to remove the debug settings when testing is complete. The verbose logs can have a negative impact on server performance.

PROBLEM or ERROR occurred and how to resolve them
Port 25 open by iptables firewall
Make sure port 25 open has been accept by iptables firewall, visit this article to Install and Set Up Iptables Firewall on Centos 6
Postfix Gmail SMTP Relay access denied

rcpt to: [email protected]
554 5.7.1 <[email protected]>: : Relay access denied

Your Google Account has been suspendedYour-Google-Account-has-been-suspended

Hi vpshelpdesk,
Google has suspended your Account, [email protected], because of a violation of our Terms of Service.

Please follow possible solution below, so far it is working for meallow-less-secure-apps-ON

Change the “allow less secure apps” setting to enable. This allows them to connect to the account again.
Insert and Verify Account recovery email and phoneVerify-Account-recovery-email-and-phone

If Gmail SMTP Relay rare to use and rare sign in sometimes the message will not deliver again. Once check tail -f /var/log/maillog, we will find error below;

May 16 14:31:43 vpsheldesk.com postfix/smtp[1096]: D738BA40BE0: to=, relay=smtp.gmail.com[74.125.138.109]:587, delay=31, delays=0.01/0.04/31/0, dsn=4.7.14, status=deferred (SASL authentication failed; server smtp.gmail.com[74.125.138.109] said: 534-5.7.14 Please log in via your web browser and?534-5.7.14 then try again.?534-5.7.14 Learn more at?534 5.7.14 https://support.google.com/mail/answer/78754 w190sm8732463ywa.39 - gsmtp)
Visit GMAIL HELP https://support.google.com/mail/answer/78754 and follow the instructions


Can’t sign in to my email app
If you’re using the wrong Gmail password on another email app, you might have these problems:

  • The app keeps asking for your username and password
  • You see an “invalid credentials” error message
  • You see a “web login required” error message

If you have these problems or can’t sign in, first check to make sure you’re using the right password.

Tip: Keep in mind that passwords are case-sensitive.
Troubleshoot sign-in problems
If you’re sure your password is right, try these tips:

  • If you’ve turned on 2-Step Verification for your account, you might need to enter an App password instead of your regular password.
  • Sign in to your account from the web version of Gmail at https://mail.google.com. Once you’re signed in, try signing in to the mail app again.
  • Visit http://www.google.com/accounts/DisplayUnlockCaptcha and sign in with your Gmail username and password. If asked, enter the letters in the distorted picture.
  • Your app might not support the latest security standards. Try changing a few settings to allow less secure apps access to your account.
  • Make sure your mail app isn’t set to check for new email too often. If your mail app check for new messages more than once every 10 minutes, the app’s access to your account could be blocked.
  • Change your password according to our tips on creating a strong password.