Setup Ubuntu Server to send email with own domain

Setup Ubuntu Server to send email with own domain

Posted: 10 years ago in  Unix | Miscellaneous |


To add "email notification" to an appplication/website, usually, the first thing is setup of sendmail on Ubuntu server. It is absolutly simple. Here is few steps to do:


To add "email notification" to an appplication/website, usually, the first thing is setup of sendmail on Ubuntu server. It is absolutly simple. Here is few steps to do:

First of all, SSH to server

Install sendmail

sudo apt-get install sendmail

Next thing to change is hosts file, it will make a difference between 2 minutes and 5s later, trust me ;-)

sudo nano /etc/hosts

add yourhostname in. It will look like:

127.0.0.1    localhost.localdomain localhost yourhostname

*Hint: what is hostname ? Take a look at the commandline cursor after you ssh, it's like "yourusername@yourhostname". This name is registered when you create/buy your server or when you install Ubuntu

Restart networking (it is not necessary to use sudo but, sometime, it ensure you successfully restart service)

sudo /etc/init.d/networking restart

Then, let sendmail init configuration:

sudo sendmailconfig

Then, 3 times of YES

Test it to see if everything is ok

Create email.txt file with content:

Subject: Terminal Email Send

Email Content line 1
Email Content line 2

Then type in commandline:

sendmail emailaddress@domain.com < /path/to/email.txt

Then check your email 8-)

There are several package to send email in Ubuntu, and one day, you might change your mind, then remove sendmail completly cannot be easier than

sudo apt-get remove sendmail sendmail-base sendmail-bin sendmail-cf sendmail-doc
sudo apt-get purge sendmail sendmail-base sendmail-bin sendmail-cf sendmail-doc