Home > mail, redmine, tutorial, ubuntu > How to install and configure Postfix on Ubuntu?

How to install and configure Postfix on Ubuntu?

I’m trying to configure an incoming email service for receiving issues via email in a Redmine server for a company.

The company uses Lotus Notes and for security reasons, I cannot read email using POP3 or IMAP, only with notes client or notes iWeb. I need an account (redmine@foocompany.org) but the company does not generate generic accounts. I neither can use a Gmail account, because they use an authenticated proxy and it’s not possible to check the gmail account (neither I can check another user’s account in the same company). Crazy!

I don’t need to send mails from this account. At least I can use their SMTP server to send the redmine’s mails.

The solution is to create a local mail transfer agent (I’ll use Postfix) in the server where redmine is installed, create a local mail account (redmine@redmineserver.foocompany.org), and then redirect all the mail from the user account that administers the redmine to this local account. A bit convoluted, I know, but I have no other choice.

Hands on!

Postfix is a well known Mail Transfer Agent (MTA), and it’s an alternative to the also widely used Sendmail MTA. We’ll use also Courier IMAP and Courier POP3 to retrieve emails. If you want a more detailed explanation, have a look at this Ubuntu HowTo:

https://help.ubuntu.com/community/PostfixBasicSetupHowto

In this post I will focus only on the installation and configuration process. This is a schema of our final result (taken from the Ubuntu HowTo):

 

Postfix schema

Postfix schema

 

Install Postfix

The first step is to install postfix:

$ sudo apt-get install postfix

You’ll be prompted for your server type. Choose “Internet site”:

Postfix - Internet site

And then enter your domain name (example.org, or in my case l3-ubuntu-12.com):

Postfix - Domain name

Once installed, edit the /etc/postfix/main.cf file and add this lines at the end of the file:


inet_protocols = ipv4
home_mailbox = Maildir/

We are telling postfix to use IPv4 protocol, and that the folder where the mail will be saved (home/username/Maildir). Extract from the Ubuntu HowTo:

Maildir is a format for an e-mail spool that does not require file locking to maintain message integrity because the messages are kept in separate files with unique names. A Maildir is a directory (often named Maildir) with three subdirectories named tmp, new, and cur. The subdirectories should all reside on the same filesystem.

Another reason to use Maildir format is that Courier IMAP/POP3 servers only work with Maildir format of mailboxes.

Restart postfix to get the new configuration:

 $ sudo service postfix restart 
* Stopping Postfix Mail Transport Agent postfix [ OK ] 
* Starting Postfix Mail Transport Agent postfix [ OK ]

Install Courer POP3 and Courier IMAP

To retrieve the emails from our MailBox, we’ll to install Courier POP3 and Courier IMAP:


$ sudo apt-get install courier-pop

When prompted for creating web-based administration directories, answer No:

 

courier-pop administration directories

Then install Courier IMAP:

 
$ sudo apt-get install courier-imap 

Install bsd-mailx

To make some tests sending emails, we need a mail client. Bsd-mailx is a simple command-line mail client:

 
$ sudo apt-get install bsd-mailx 

Install Mozilla Thunderbird

Finally, to make the final tests, we’ll install Mozilla Thunderbird. If you haven’t already installed, just type:

 
$ sudo apt-get install thunderbird

Testing the installation

First of all, test your mail server:


$ telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 l3-ubuntu-12 ESMTP Postfix (Ubuntu)
quit
221 2.0.0 Bye
Connection closed by foreign host.

Lets create some users to test our mail server. Answer the questions to create the users:

 
$ sudo adduser user1
$ sudo adduser user2

Now change to user1 and send an email to user2:

  • To send a mail to user2, type mail user2
  • Write the subject of the email and press [Enter]
  • Write the body of the email and press [Enter]
  • To send the mail, write a dot (.) and press [Enter]
$ su user1
Password: 
user1@l3-ubuntu-12:/home/user1$ mail user2
Subject: test mail from user1
This is a test mail from user1
.
EOT

Now check if the email has arrived to user2. To avoid the “Cannot open display” message:

$ su user2
Contrasenya: 
user2@l3-ubuntu-12:/home/user2$ thunderbird 
No protocol specified
No protocol specified
No protocol specified
No protocol specified
Error: cannot open display: :0

switch to user2 with sux. Sux is a wrapper around su to transfer your X credentials, thus you can open Thunderbird with user2 (install with sudo apt-get install sux):

$ sux user2
Password: 
xauth: file /home/user2/.Xauthority does not exist
user2@l3-ubuntu-12:/home/user2$ thunderbird

Open Thunderbird and create a new account:

Press Skip this and use my existing email:

Thunderbird-New account

Enter the user2 account settings:

Thunderbird - user2 account settings

Press Continue. If you get this error:

Thunderbird failed to find the settings for your email account

Thunderbird - Error

 

Then restart postfix and try again:

$ sudo service postfix restart

Now the configuration must be retrieved. I choose the POP3 configuration for my email account:

Thunderbird - correct settings
And press Done. You get this warning screen because we are not using encryption (maybe in a later post, for the purpose of testing the email it’s enough with this). Check I understand the risks and press Done.

Thunderbird - warning screen

And now you can retrieve the email for user2.

Thunderbird - Inbox

If you try to send a message you’ll get this error:

 

Thunderbird - Error sending mail

 

You have to get the local certificate and confirm the security exception to send mails:

Thunderbird - Confirm ecurity exception

 

And now just pray for this to work in the foo company!

Do you liked this HowTo? PLease leave your comments below.

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: