Nico Amarilla

My personal notes on programming.

Install Sendmail on Ubuntu And Why Is It So Slow?

Featured Sendmail Slow

When building a web app that will have registered users, you will need to have a way to send email to users during sign-up. The number one reason is to confirm that their email address is valid. Another reason is to have a “forgot password” feature.

If you are on a shared hosting, there is no need to set this up. But if your on a VPS, you may need to setup your own SMTP server. Now, there are many options out their, like Amazon SES and Mailgun, but they will cost you a little bit of extra cash.

In my case, I wanted to try out sendmail on a Digital Ocean droplet. Although this doesn’t cost a dime, it will cost more time to setup! To save you some trouble, here’s what I did:

Install

Login into your droplet and do the following:

  1. Update ubuntu
    sudo apt-get update
  2. Install sendmail
    sudo apt-get install sendmail
  3. Configure /etc/hosts:

    nano /etc/hosts

    Find this line:

    127.0.0.1 localhost

    Make sure that it looks like this:

    127.0.0.1 localhost.localdomain localhost yourhostname

    Change yourhostname to the name of your droplet.

  4. Run Sendmail’s config and answer ‘Y’ to everything:
    sudo sendmailconfig

Test

  • Type this in the console:
    echo "test message" | sendmail -v recipient@mail.com

    Change recipient@mail.com to the receiving email address.

  • Check your inbox. Most probably its in the spam folder if your domain has no reputation yet.

Why is Sendmail So Slow?

This happened while I was testing. Sendmail is very slow, an upwards of 60 secs in sending a single mail!

To solve it you need to make sure that you change the localhost entry in /etc/hosts. In Digital Ocean it has an additional entry:

127.0.0.1 droplet-name-goes-here

Comment that out and only have a single 127.0.0.1. See number 3 in the install section above.

 

Using It In A Web App

In my case, I built my app with nodejs. I installed nodemailer and use the sendmail transport. The docs are pretty straightforward. If you are on PHP you can just use the mail() function.

That’s it for now.

No Comments

Leave a Reply

Your email address will not be published. Required fields are marked *