In my last post I showed a particularly easy way to 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 rough spots 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 roughly 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 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 their 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 must 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 student@ubuntu, 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 smtp_generic_maps=texthash:/etc/postfix/generic
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:
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!