Configure sendmail in Ubuntu 12.04 and make it fast!

I got a server in DigitalOcean and installed WordPress.

To my surprise, sending mail was not something pre-configured so I had to find a way. I did not want to use SMTP solutions but use a simple Unix package such as sendmail or postfix.

It seems that sendmail is simpler, and good enough if you only want to send mails. That is my case, because I just want to receive notifications from WP, such as the ones that contact form 7 sends everytime a form is filled up and sent.

So I looked at tutorials, and the simplest thing to do was

1) If sendmail is not installed, do install it:
apt-get install sendmail
2) Configure hosts file correctly:
nano /etc/hosts
And make sure the line looks like this:
127.0.0.1 localhost localhost.localdomain yourhostnamehere
3) Reload /etc/hosts, so that the previous changes take effect
sudo /etc/init.d/networking restart that works but seems to be deprecated, better use:
/etc/init.d/networking stop
/etc/init.d/networking start

4) Run the sendmail config and answer ‘Y’ to everything:
sendmailconfig

source: https://www.digitalocean.com/community/questions/php-mail-function-enable

Thanks to Colling Henderson for the help, which I also found when digging further about the sluggishness of sendmail, in his blog: http://collinhenderson.com/post/48046976172/a-fix-for-slow-sendmail-on-ubuntu

It is of utmost importance that you make sure the of point 2 string “localhost.localdomain” is in there. I did not take it seriously the first time I read it, but it does make a big difference. If you don’t change it, the php send function will be sooooo slow.

By the way, I also followed the instructions here: http://www.devraju.com/php/slow-email-sending-in-ubuntu-12-04-lts-solution/ and I am not sure how much changing the line in the sendmail.cf is affecting the speed. To me it was the fact that the string “localhost.localdomain” what really made the difference from some 1 minute to 2 seconds!!!!

7 thoughts on “Configure sendmail in Ubuntu 12.04 and make it fast!

  1. I never even ran “sendmailconfig”. Did sudo apt-get install sendmail, the hosts thing as you mentioned, and then did this for a simple test:
    echo “This is a test.” | mail -s Testing email@address.tld

    email@address.tld should receive an email with a body of “This is a test.” and a subject of “Testing”.

    Just an easy way to test that it all worked. You may have to install the “mailutils” package if the “mail” command isn’t available. It’s included in “mailutils”.

    I’ve been doing a bit of testing lately, because this solution still seems to elude many people. This seems to be the easiest way to go about getting emails to send from PHP, at least on a relatively stock Ubuntu LAMP Droplet.

  2. Esteban Gatjens says:

    I want to share an issue that i have with this setup.

    My server was added to the CBL list, because is sending mails identifying themselves as localhost.localdomain. [http://www.abuseat.org/namingproblems.html]

    The way to fix this is defining confDOMAIN_NAME into /etc/mail/sendmail.mc file:

    define(`confDOMAIN_NAME’, `app05.site.com’)dnl

    then:
    $ make -C /etc/mail/

    and reload
    $ /etc/init.d/sendmail reload

    Thanks for your article, this really help me!

  3. ziki42 says:

    Just wanted to say that after calling “/etc/init.d/networking stop” , the network interface stops and you are disconnected and cannot access the server anymore. You should have written a warning there or something

Leave a comment