Local SMTP server for ubuntu

Configure the E-mail Options tab of the Site Administration page: In the Sending E-mail Status list, select Active or Inactive, as appropriate. In the Mail Transport Type list, select SMTP. In the SMTP Host field, enter the name of your SMTP server.

Local SMTP server for ubuntu

Steps for setting up an SMTP relay on Ubuntu

In this tutorial, we’ll demonstrate setting up SMTP relay with Mailjet’s free plan on a Ubuntu server. But the steps should be similar for the other service providers as well.

Step 1: Install postfix SMTP server

First we’ll need to setup a local SMTP server, which we’ll do so by setting up postfix which is a popular open source mail transfer agent. We can easily install postfix by running the apt command:

1
sudo apt install postfix

When you enter the command above, postfix‘s configuration window will open, like below:

Postfix Configuration
Postfix Configuration

The postfix configuration asks you for what kind of a service are you setting up postfix for, so it can configure itself for your best needs. In this tutorial we’ll go with “Internet Site” as we are required to send emails over the internet. So you can simply press Enter key.

Now next you are required to enter the domain name for your email service, it should be a fully qualified domain name (FQDN).

Enter Mail Domain Name
Enter Mail Domain Name

and then it will run the script to put up the best configuration according to your needs and the inputted data.

Step 2: Creating Mailjet free account for our SMTP relay on Ubuntu

We are done installing with postfix but before we continue configuring postfix we’ll need to first get the required credentials to be successfully able to configure postfix for SMTP relay.

For demonstration, we’ll register a free account on Mailjet. But the process will be similar for the other providers as well, once you are done with the registration.

Choose as Developer, and in “Sending methods” choose “SMTP relay”. Once you have chosen SMTP relay as your sending method. They’ll give give you the required details:

SMTP Relay Credentials
Mailjet’s SMTP relay Credentials

Step 3: Authenticate your domain name

You must authenticate your domain name to improve emails deliverability and that your emails don’t end up in spam.

Authenticate Your Domain Name
Authenticate your domain name

Step 4: Configuring postfix for SMTP relay on Ubuntu

Now we have the required credentials, so we can get started to configure postfix to send all the emails through the SMTP relay.

We need to make following changes in the /etc/postfix/main.cf which is the postfix’s configuration file. First you need to find relayhost in main.cf configuration and enter your relay host,

Change Relayhost In Postfix Configuration To Your Own Service Provider 2
Change relayhost to the SMTP relay host

In our case, we’ve used the host provided by the Mailjet. But it will be different for different providers, so make sure you enter the right relayhost.

Now add the following to the main.cf file, to enable SASL authentication,

1
2
3
4
5
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

You can read more about these settings in the postfix’s documentation. Once you are done, save the file.

Step 5: Setting up credentials for SASL authentication

Now we’ll create a file at /etc/postfix/sasl_passwd and add the credentials in the following format in plain text form:

1
[smtp.example.com]:port user:pass
SASL Authentication Credentials
SASL Authentication Credentials

Now we’ll hash the database file using the postmap command:

1
sudo postmap /etc/postfix/sasl_passwd

Next, restart postfix,

1
sudo service postfix restart

We are done with configuring SMTP relay!

Sending a test email

So that now we are done with configuring SMTP relay, now it’s time to put it to test, for this purpose we’ll send a test email using mail command, if you cannot find mail command, you can simply install it by install mailutils with apt command:

1
sudo apt install mailutils

now to send an email enter:

1
echo "This is the email body!" | mail -s "Subject of your email" -a "From: sender@example.com" receiver@example.com

If you receive the email, congratulations you have successfully setup SMTP relay server! Incase you didn’t receive email, you can find mail logs in /var/log/mail.log which will help in troubleshooting.

Conclusion

And that brings us to the end of this article! We hope you enjoyed learning with us! There’s a lot more in store for Linux tutorials in the future so stay tuned!


Click Here to Visit

What's Your Reaction?

like
0
dislike
0
love
0
funny
0
angry
0
sad
0
wow
0