How To Install And Configure Sendmail On Ubuntu

1. Install Sendmail

$ sudo apt-get install sendmail

2. Configure /etc/hosts file:

Find your hostname by typing:

$ hostname


$ sudo nano /etc/hosts

On the line starting with, add the hostname to the end so it looks the same as: localhost hostname

(You willl notice that your hostname can also be identified on the line that starts with where it appears twice)

Ctrl+x, then ‘Y’ to save and exit.

3. Run Sendmail’s config and answer ‘Y’ to everything:

$ sudo sendmailconfig

4. Restart Apache

$ sudo service apache2 restart

5. Using sendmail:

To quickly send an email:

$ sendmail -v

After hitting the enter key, on the line directly below, enter a From address (each line after you hit enter will be blank):


Hit enter again and type a subject:

Subject: This is the subject field of the email

Hit enter again and type the message:

This is the message to be sent.

Hit enter again. To send the email, type a ‘.‘ (period/dot) on the empty line and press enter:


Wait a few seconds and you will see the output of the email being sent. To see more usage examples, check out the links below.


If you can not send mail.

When sending emails from your server, make sure to check any spam folders for receipt. If email is for some reason not working, try the steps below:

4 sudo nano /etc/php/7.0/fpm/php.ini

Ctrl+w to search for and find ‘sendmail_path’. Uncomment this line and add the path below:

sendmail_path= /usr/sbin/sendmail -t -i

Restart php:

$ sudo service php7.0-fpm restart


Develop and scale your apps globally with DigitalOcean and/or Vultr – or use shared hosting with no server maintenance required at

Installation & Maintenance

If you would like to get this app installed, maintained or need training, Contact Me to get current rates.

5 thoughts on “How To Install And Configure Sendmail On Ubuntu

    1. Hello, localhost is your server which sendmail uses to send the email. The post has been updated to reflect a basic usage example that includes a ‘From’ field. To configure sendmail to always use a specific email address, check out this link at where you would create a template file, for example:

      $ cd ~
      $ sudo nano mail.txt

      with some content like:

      Subject: sendmail test
      And here goes the e-mail body, test test test..

      and send email with:

      $ sendmail -vt < ~/mail.txt
  1. Hi all – I’ve always had trouble with sendmail – but I thought I would try again with a new server
    When you config it you are supposed to say ‘Y’ to everything – there no option to to add/change parameters.
    Hence I get ‘connection timed out’ message – In NZ port 25 is not allowed .
    Question – were is the parameters file to change sendmail configuration.
    Much appreciated.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.