Bobcares

Digitalocean SMTP relay | All About

by | Sep 17, 2022

With help of our Digital Ocean Support Team let’s work on the Digitalocean SMTP relay. You will install and configure Postfix as a send-only SMTP serve. At Bobcares, we handle all kinds of requests from our customers no matter how trivial.

Digitalocean SMTP relay 

Postfix is a mail transfer agent which is an application used to send and receive email. Also, can be configured so that you can send emails by local application. This application is useful when you send email notifications regularly or have a lot of outbound traffic that a third-party email service provider won’t allow.

Digitalocean SMTP relay 

Step 1 — Installing Postfix

 

Initially, you’ll have to install Postfix. Before installation you would have to update the package database:

 
sudo apt update
 

Now, install Postfix by running the below command:

 
sudo apt install mailutils
 

While the end of the installation process, you will be displayed with the Postfix configuration window with 4 general type of mail configuration options

 

The default option is Internet Site. That’s the suggested option for use, so press TAB >> and then ENTER. If you get only the description text then press TAB to select OK and click on ENTER.

 

You have now successfully installed Postfix and next, we will configure it in the second step.

 

Step 2 — Configuring Postfix

 

In this process, you will configure Postfix to send and receive emails only from the local server on which it is running

 

Further, you need to configure Postfix to listen on the loopback interface. Usually, the virtual network interface server uses to communicate internally. To make the changes, you’ll need to edit the main Postfix configuration file called main.cf that is put down under “etc/postfix“.

 
sudo nano /etc/postfix/main.cf
 

Next, find the following lines:

/etc/postfix/main.cf

. . .
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
. . .
 

and then configure the value of "inet_interfaces" setting to "loopback-only":

 

/etc/postfix/main.cf

. . .
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = loopback-only
. . .
 

If you want a subdomain to send email messages that look as if they were sent from the main domain then you can add the following line to the end of main.cf:

 

/etc/postfix/main.cf

...
masquerade_domains = main_domain
 

The optional masquerade_domains setting indicates the domain for which the subdomain will be stripped off in the email address.

 

Once these are updated save and close the file. Then restart Postfix:

 
sudo systemctl restart postfix
 

You have successfully set Postfix to send emails from your server. You will next test by sending a test message to an email address.

 

Step 3 — Testing the SMTP Server

 

In this step, you will test by sending emails to an external email account using the mail command. Run the below command tp send a test email message:

 
echo "Body of the email" | mail -s "Subject line" Email_address 
 

Now, check your inbox to which email address you have added.

 

Step 4 — Forwarding System Mail

 

In this step, you’ll set up a function of email forwarding for user root, so that system-generated messages sent to server will forward to an external email address.

 

The /etc/aliases file contains a list of alternate names for email recipients, open it for editing and add the below line to the end of the file:

 

/etc/aliases

...
root:          Email_address
 

With this line, you will specify that emails that are sent to the root will be forwarded to an email address. Replace Email_address with your personal email address.  Save the file.

 

Run the given command for the changes to take effect:

 
sudo newaliases
 

By Running newaliases will build up a database of aliases that the mail command uses, which are basically taken from the config file you just edited.

 

Now test the forwarding emails:

 
echo "Body of the email" | mail -s "Subject line" root
 

You should be receiving the email to your email address, If it’s not dropped in your inbox then check your spam folder.

 

[Looking for a solution to another query? We are just a click away.]

 

Conclusion

 

You now have now a Postfix mail transfer agent to send-only email server with forwarding emails from user root. Also a lighter alternative to run a full-blown SMTP server while retaining the required functionality.

 

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

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

Never again lose customers to poor
server speed! Let us help you.