Select Page

Advent

Postfix is a well-liked open-source Mail Switch Agent (MTA) that can be utilized to path and ship e-mail on a Linux machine. It’s estimated that round 25% of public mail servers on the net run Postfix.

On this information, we will train you methods to stand up and working temporarily with Postfix on an Ubuntu 18.04 server.

Must haves

As a way to practice this information, you’ll have get admission to to a non-root person with sudo privileges. You’ll practice our Ubuntu 18.04 initial server setup guide to create the essential person.

As a way to correctly configure Postfix, you’re going to want a Absolutely Certified Area Title pointed at your Ubuntu 18.04 server. You’ll to find assist on putting in place your area title with DigitalOcean via following this guide. For those who plan on accepting mail, it is very important remember to have an MX file pointing on your mail server as smartly.

For the needs of this instructional, we can think that you’re configuring a bunch that has the FQDN of mail.instance.com.

Step 1 — Set up Postfix

Postfix is integrated in Ubuntu’s default repositories, so set up is discreet.

To start out, replace your native apt bundle cache after which set up the instrument. We will be able to be passing within the DEBIAN_PRIORITY=low environmental variable into our set up command in an effort to resolution some further activates:

  • sudo apt replace
  • sudo DEBIAN_PRIORITY=low apt set up postfix

Use the next knowledge to fill to your activates appropriately on your surroundings:

  • Normal form of mail configuration?: For this, we can make a selection Web Web site since this suits our infrastructure wishes.
  • Device mail title: That is the bottom area used to build a legitimate e-mail deal with when handiest the account portion of the deal with is given. As an example, the hostname of our server is mail.instance.com, however we most definitely wish to set the machine mail title to instance.com in order that given the username user1, Postfix will use the deal with user1@instance.com.
  • Root and postmaster mail recipient: That is the Linux account that will likely be forwarded mail addressed to root@ and postmaster@. Use your number one account for this. In our case, sammy.
  • Different locations to simply accept mail for: This defines the mail locations that this Postfix example will settle for. If you wish to have so as to add some other domain names that this server will likely be answerable for receiving, upload the ones right here, differently, the default must paintings high-quality.
  • Drive synchronous updates on mail queue?: Because you are most likely the use of a journaled filesystem, settle for No right here.
  • Native networks: It is a listing of the networks that your mail server is configured to relay messages for. The default must paintings for many eventualities. If you select to change it, remember to be very restrictive regarding the community vary.
  • Mailbox dimension prohibit: This can be utilized to restrict the scale of messages. Surroundings it to “0” disables any dimension restriction.
  • Native deal with extension personality: That is the nature that can be utilized to split the common portion of the deal with from an extension (used to create dynamic aliases).
  • Web protocols to make use of: Make a selection whether or not to limit the IP model that Postfix helps. We will pick out “all” for our functions.

To be particular, those are the settings we will use for this information:

  • Normal form of mail configuration?: Web Web site
  • Device mail title: instance.com (now not mail.instance.com)
  • Root and postmaster mail recipient: sammy
  • Different locations to simply accept mail for: $myhostname, instance.com, mail.instance.com, localhost.instance.com, localhost
  • Drive synchronous updates on mail queue?: No
  • Native networks: 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
  • Mailbox dimension prohibit: 0
  • Native deal with extension personality: +
  • Web protocols to make use of: all

If you wish to have to ever go back to re-adjust those settings, you’ll accomplish that via typing:

  • sudo dpkg-reconfigure postfix

The activates will likely be pre-populated along with your earlier responses.

When you find yourself completed, we will be able to now do a little extra configuration to arrange our machine how we might adore it.

Step 2 — Tweak the Postfix Configuration

Subsequent, we will be able to alter some settings that the bundle didn’t recommended us for.

To start out, we will be able to set the mailbox. We will be able to use the Maildir structure, which separates messages into particular person recordsdata which can be then moved between directories according to person motion. The opposite choice is the mbox structure (which we would possibly not duvet right here) which retail outlets all messages inside a unmarried report.

We will be able to set the home_mailbox variable to Maildir/ which can create a listing construction beneath that title inside the person’s house listing. The postconf command can be utilized to question or set configuration settings. Configure home_mailbox via typing:

  • sudo postconf -e 'home_mailbox= Maildir/'

Subsequent, we will be able to set the positioning of the virtual_alias_maps desk. This desk maps arbitrary e-mail accounts to Linux machine accounts. We will be able to create this desk at /and so on/postfix/digital. Once more, we will be able to use the postconf command:

  • sudo postconf -e 'virtual_alias_maps= hash:/and so on/postfix/digital'

Step 3 — Map Mail Addresses to Linux Accounts

Subsequent, we will be able to arrange the digital maps report. Open the report to your textual content editor:

  • sudo nano /and so on/postfix/digital

The digital alias map desk makes use of a very easy structure. At the left, you’ll listing any addresses that you simply want to settle for e-mail for. Afterwards, separated via whitespace, input the Linux person you would like that mail dropped at.

As an example, if you need to simply accept e-mail at touch@instance.com and admin@instance.com and want to have the ones emails dropped at the sammy Linux person, it is advisable arrange your report like this:

/and so on/postfix/digital

touch@instance.com sammy
admin@instance.com sammy

After you have mapped the entire addresses to the correct server accounts, save and shut the report.

We will observe the mapping via typing:

  • sudo postmap /and so on/postfix/digital

Restart the Postfix procedure to make sure that all of our adjustments were carried out:

  • sudo systemctl restart postfix

Step 4 — Regulate the Firewall

If you’re working the UFW firewall, as configured within the preliminary server setup information, we will have to permit an exception for Postfix.

You’ll permit connections to the provider via typing:

The Postfix server element is put in and in a position. Subsequent, we can arrange a consumer that may maintain the mail that Postfix will procedure.

Step 5 — Putting in place the Setting to Fit the Mail Location

Earlier than we set up a consumer, we must ensure our MAIL environmental variable is ready appropriately. The buyer will check up on this variable to determine the place to search for person’s mail.

To ensure that the variable to be set without reference to the way you get admission to your account (via ssh, su, su -, sudo, and so on.) we wish to set the variable in a couple of other places. We will upload it to /and so on/bash.bashrc and a report inside /and so on/profile.d to verify each and every person has this configured.

So as to add the variable to those recordsdata, kind:

  • echo 'export MAIL=~/Maildir' | sudo tee -a /and so on/bash.bashrc | sudo tee -a /and so on/profile.d/mail.sh

To learn the variable into your present consultation, you’ll supply the /and so on/profile.d/mail.sh report:

  • supply /and so on/profile.d/mail.sh

Step 6 — Set up and Configure the Mail Consumer

As a way to have interaction with the mail being delivered, we can set up the s-nail bundle. It is a variant of the BSD xmail consumer, which is feature-rich, can maintain the Maildir structure appropriately, and is most commonly backwards suitable. The GNU model of mail has some boundaries, reminiscent of all the time saving learn mail to the mbox structure without reference to the supply structure.

To put in the s-nail bundle, kind:

We must alter a couple of settings. Open the /and so on/s-nail.rc report to your editor:

In opposition to the ground of the report, upload the next choices:

/and so on/s-nail.rc

. . .
set emptystart
set folder=Maildir
set file=+despatched

This may increasingly permit the customer to open even with an empty inbox. It is going to additionally set the Maildir listing to the inner folder variable after which use this to create a despatched mbox report inside that, for storing despatched mail.

Save and shut the report if you end up completed.

Step 7 — Initialize the Maildir and Check the Consumer

Now, we will be able to take a look at the customer out.

Initializing the Listing Construction

One of the best ways to create the Maildir construction inside our house listing is to ship ourselves an e-mail. We will do that with the s-nail command. For the reason that despatched report will handiest be to be had as soon as the Maildir is created, we must disable writing to that for our preliminary e-mail. We will do that via passing the -Snorecord choice.

Ship the e-mail via piping a string to the s-nail command. Regulate the command to mark your Linux person because the recipient:

  • echo 'init' | s-nail -s 'init' -Snorecord sammy

You might get the next reaction:

Output

Can not canonicalize "/house/sammy/Maildir"

That is customary and might handiest seem when sending this primary message. We will take a look at to verify the listing was once created via in search of our ~/Maildir listing:

You must see the listing construction has been created and {that a} new message report is within the ~/Maildir/new listing:

Output

/house/sammy/Maildir/: cur new tmp /house/sammy/Maildir/cur: /house/sammy/Maildir/new: 1463177269.Vfd01I40e4dM691221.mail.instance.com /house/sammy/Maildir/tmp:

It seems like our mail has been delivered.

Managing Mail with the Consumer

Use the customer to test your mail:

You must see your new message ready:

Output

s-nail model v14.8.6. Sort ? for assist. "/home/sammy/Maildir": 1 message 1 new >N 1 sammy@instance.com Wed Dec 31 19:00 14/369 init

Simply hitting ENTER must show your message:

Output

[-- Message 1 -- 14 lines, 369 bytes --]: From sammy@instance.com Wed Dec 31 19:00:00 1969 Date: Fri, 13 Might 2016 18:07:49 -0400 To: sammy@instance.com Matter: init Message-Identity: From: sammy@instance.com init

You’ll get again on your message listing via typing h, after which ENTER:

Output

s-nail model v14.8.6. Sort ? for assist. "/home/sammy/Maildir": 1 message 1 new >R 1 sammy@instance.com Wed Dec 31 19:00 14/369 init

Since this message is not very helpful, we will be able to delete it with d, after which ENTER:

Hand over to get again to the terminal via typing q after which ENTER:

Sending Mail with the Consumer

You’ll take a look at sending mail via typing a message in a textual content editor:

Inside of, input some textual content you would love to e-mail:

~/test_message

Hi,

It is a take a look at.  Please verify receipt!

The usage of the cat command, we will be able to pipe the message to the s-nail procedure. This may increasingly ship the message as your Linux person via default. You’ll alter the “From” box with the -r flag if you wish to regulate that price to one thing else:

  • cat ~/test_message | s-nail -s 'Check e-mail matter line' -r from_field_account person@e-mail.com

The choices above are:

  • -s: The topic line of the e-mail
  • -r: An non-compulsory exchange to the “From:” box of the e-mail. Through default, the Linux person you might be logged in as will likely be used to populate this box. The -r choice lets you override this.
  • person@e-mail.com: The account to ship the e-mail to. Alternate this to be a legitimate account you could have get admission to to.

You’ll view your despatched messages inside your s-nail consumer. Get started the interactive consumer once more via typing:

Afterwards, view your despatched messages via typing:

You’ll arrange despatched mail the use of the similar instructions you utilize for incoming mail.

Conclusion

You must now have Postfix configured in your Ubuntu 18.04 server. Managing e-mail servers could be a tricky process for starting directors, however with this configuration, you’ll have fundamental MTA e-mail capability to get you began.