Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.

Channels ▼

Mark Nelson

Dr. Dobb's Bloggers

SMTP Configuration

July 22, 2011

In my last post I showed a particularly easy way to set up an SMTP server so postfix could send mail from your Linux system. In this post I'm going to add a few tips that might help you get through some rough spots in the whole process.

Results From the Field

After writing a HOWTO page, there is no better test of its quality than to try it out with a group of students performing the task for the first time. That's just what I did with my SMTP configuration post — I created a homework problem that asked my students to set up outbound email on their personal Linux systems.

Their resulting glitches highlighted a few difficulties in the process, most of which can be handled pretty easily.

Debian Package Configuration

When you install postfix on Ubuntu, you will normally get kicked into a simple package configuration dialog after the package has been downloaded and installed. This final step performs some very basic setup on postfix, getting into a basically functional state.

If this configuration doesn't run, postfix seems to be configured to only handle local mail — messages from one user to another. In some cases this may be just what you want, but normally it is not all that useful.

For unknown reasons, this configuration pass doesn't always kick off properly. I've seen it fail to run, and some students have as well. Fortunately, you can execute the same process by hand from the command line:

sudo dpkg-reconfigure postfix

Running through this, I take the default settings for everything except Root and postmaster mail recipient, which I change to student, the name of my account on this system. After this is complete, following the instructions from my previous post will give you a proper Internet email setup.

Using Mailjet Instead of SendGrid

After some glitches getting accounts on SendGrid, I had a couple of students decide to use Mailjet as an STMP provider. Registering with Mailjet is easier, as it is an automated process. However, using Mailjet as your SMTP provider comes with a couple of interesting twists.

First, instead of using your Mailjet account credentials to authenticate with its SMTP server, Mailjet gives you a set of strong credentials specifically for SMTP authentication. You have to copy these from your Account Info page. No problem there, as long as you RTFM.

Slightly more problematic is that Mailjet insists that the return address you use in your outbound emails be an authenticated address. In other words, you have to be able to receive an email sent to that address and click on an authentication link.

When using postfix's default settings, email sent by my students was going out with a return address of [email protected], and there is obviously no way to authenticate that address. So we have to rewrite that address to something usable.

After taking that additional requirement into account, my changes to /etc/postfix/main.cf for Mailjet are shown below. The file had a default relayhost entry, which is replaced, and the remaining lines are all new. The username and password have to be replaced with the ones from your Mailjet account page:

smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = static:username:password
smtp_sasl_security_options = noanonymous
smtp_tls_security_level = may
relayhost = [in.mailjet.com]:587

The last line I added to the configuration tells postfix to look in a file called /etc/postfix/generic for a list of substitutions to make to email addresses found in headers being processed. I create a single line in this file:

[email protected] [email protected]

This entry in the map file changes the local student account to an authenticated email address. After making this change, emails sent from the student account will have their headers rewritten to give a sender identity of your personal email address, which means Mailjet will happily forward your messages to their final destination.

Once that's done, I restart postfix and send a test message:

sudo /etc/init.d/postfix restart
echo hello | mailx -s "test mail" myemailaddress

The headers on my received email show that things worked more or less as expected:

One nice thing about using the generic substitution file is that now you can accommodate different sender email addresses for every account on your system. Since you have to enter account info by hand, this doesn't scale to a large enterprise, but it works just fine for your personal system.

There's no doubt that the complexities of managing mail on a Linux system is still a bit daunting, but at least the process of simply getting outbound mail working is manageable. Give it a shot!

Related Reading

More Insights

Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.