title

How to setup Sendmail as a smarthost on Ubuntu LTS

Posted in "News"Ubuntu mail sendmail

This article was last updated on Saturday 25th of April 2020 @ 16:15 PM CEST
image 1

Some Internet service providers (ISP) do not allow you to have a working mail server due to anti-spam policies, they block all outgoing traffic on port 25.

However, you can use the mail server of your ISP to send your mails. In this article I will describe how to set up sendmail as a smarthost.

 

1. Install sendmail.

First we need to install sendmail:

sudo apt install sendmail

Just answer the default prompts to finish your installation.

 

2. Configuring sendmail as a smarthost.

Open your sendmail config using nano:

sudo nano /etc/mail/sendmail.mc

Find the line that starts with MAILER_DEFINITIONS and add following lines below:

define(`SMART_HOST', <smarthost>)dnl

As a smarthost you need to use the outgoing mailserver of your ISP, see the example below:

define(`SMART_HOST',`relay.skynet.be')dnl

 

To use the configuration changes you have made, you need to regenerate the sendmail.cf:

sudo bash -c "cd /etc/mail/ && m4 sendmail.mc > sendmail.cf"

Now restart Sendmail:

sudo systemctl restart sendmail.service

Send a mail from terminal to check if your configuration works, replace email@domain with your email address and hit CTRL + D to send the mail:

mail -s "Subject" email@domain.com

You can check your mail log for errors:

sudo tail -400 /var/log/mail.log

 

3. Send mails from PHP.

If you have a webserver running on your Ubuntu installation and you want to send mails from PHP, you need to make some changes to the php.ini file to make it work! Open the php configuration (php.ini *):

sudo nano /etc/php5/apache2/php.ini

* Your php.ini location depends on your PHP version!

 

Now find the line that contains the sendmail arguments (search for "sendmail" using CTRL + W in nano) and change sendmail path = to this:

sendmail_path = /usr/sbin/sendmail -t -i -f root@<yourdomain.ext>

for example:

sendmail_path = /usr/sbin/sendmail -t -i -f root@geoffke.be

Save the changes (CTRL + X) and restart apache:

sudo systemctl restart apache2.service

 

4.logging.

You can check if mails are delivered to the configured "smarthost" by viewing the mail log:

sudo tail -f /var/log/mail.log 
Article was posted on Monday 29th of August 2011 @ 06:47 AM CEST   comment(s)

 TVheadend Forum Migration Notice

XML error: Invalid document end at line 37