Saturday, January 23, 2010

Postfix SMTP Server Setup Howto for RHEL/CentOS 5

SkyHi @ Saturday, January 23, 2010

Installing and setting up Postfix SMTP Server in Red Hat Enterprise Linux 5 or CentOS 5 is easy. Postfix has secure default settings so we just need to open it up a bit.

Install Postfix and Mail Transport Agent Switcher

Package Management
1. If you did not add postfix and system-switch-mail-gnome during the CentOS installation, you can add it now using Package Manager tool.

Switch to Postfix from Sendmail

By default, Sendmail is the active SMTP server. Here’s how to change it.

Mail Transport Agent Switcher Shortcut
1. Click System, select Administration, and click Mail Transport Agent Switcher. This will launch the system-switch-mail window.
Mail Transport Agent Switcher
2. In the system-switch-mail window, select Postfix and click Ok.

Configure Postfix

File Browser
1. Click Applications, select System Tools then click File Browser. This will launch the File Browser window.
File Browser
2. In the Location field, type in /etc/postfix and press Enter. If you don’t see the Location field, click the notepad button to toggle to text-based location bar.
Edit main.cf
3. Double click on the file main.cf to open it for editing. We need to make it listen to network request, accept mails bound to our domain and use maildir which is a better mailbox format than mbox the default.
Find the following keys and change its values as follows
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
home_mailbox = Maildir/

In main.cf, lines starting with # are comments. Save the file after completing your changes.

NoteMake sure that all mail_spool_directory lines are commented out. Otherwise, it will override the setting in the home_mailbox line above.
Service Configuration
4. Restart the postfix service. Learn how to restart services here.

Test Postfix

Terminal
1. Click Applications, select Accessories, and click Terminal. This will launch the Terminal window.
Terminal
2. In the Terminal window, type in the highlighted commands below.

Sample postfix session. Replace johndoe with any valid user account. The dot after the line test is a command that should be typed in.

NoteIf you need to add new user accounts, learn how to add or remove user accounts here.
[root@mail ~]# telnet localhost smtp
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 mail.acme.local ESMTP Postfix
ehlo host
250-mail.acme.local
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
mail from: johndoe
250 2.1.0 Ok
rcpt to: johndoe
250 2.1.5 Ok
data
354 End data with .
test
.
250 2.0.0 Ok: queued as 9729067C17
quit
221 2.0.0 Bye
Connection closed by foreign host.
[root@mail ~]#

To check if the mail indeed exists

[root@mail ~]# cd /home/johndoe/Maildir/new
[root@mail new]# ls
1185669817.Vfd00I18012M795756.mail.acme.local
[root@mail new]# cat 1185669817.Vfd00I18012M795756.mail.acme.local

Don’t worry, you don’t have to type in the whole filename above. Just type in the first few characters say 118 then press Tab to activate automatic completion.

From johndoe@mail.acme.local  Thu Feb 22 21:48:28 2007
Return-Path:
X-Original-To: johndoe
Delivered-To: johndoe@mail.acme.local
Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
by mail.acme.local (Postfix) with SMTP id 9729067C17
for ; Thu, 22 Feb 2007 21:48:26 -0500 (EST)
Message-Id: <20070222134827.9729067c17@mail.acme.local>
Date: Thu, 22 Feb 2007 21:48:26 -0500 (EST)
From: johndoe@mail.acme.local
To: undisclosed-recipients:;

test

[root@mail mail]#