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.
Step 1 — Installing Postfix
Initially, you’ll have to install Postfix. Before installation you would have to update the package database:
sudo apt update
Copy Code
Now, install Postfix by running the below command:
sudo apt install mailutils
Copy Code
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
Copy Code
. That’s the suggested option for use, so press TAB
Copy Code
>> and then ENTER
Copy Code
. If you get only the description text then press TAB
Copy Code
to select OK
Copy Code
and click on ENTER
Copy Code
.
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
Copy Code
“.
sudo nano /etc/postfix/main.cf
Copy Code
Next, find the following lines:
/etc/postfix/main.cf
. . . mailbox_size_limit = 0 recipient_delimiter = + inet_interfaces = all . . .
Copy Code
and then configure the value of
"inet_interfaces"
Copy Code
setting to "loopback-only"
Copy Code
:
/etc/postfix/main.cf
. . . mailbox_size_limit = 0 recipient_delimiter = + inet_interfaces = loopback-only . . .
Copy Code
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
Copy Code
:
/etc/postfix/main.cf
...
masquerade_domains = main_domain
Copy Code
The optional
masquerade_domains
Copy Code
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
Copy Code
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
Copy Code
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
Copy Code
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
Copy Code
With this line, you will specify that emails that are sent to the root will be forwarded to an email address. Replace
Email_address
Copy Code
with your personal email address. Save the file.
Run the given command for the changes to take effect:
sudo newaliases
Copy Code
By Running
newaliases
Copy Code
will build up a database of aliases that the mail
Copy Code
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
Copy Code
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.
0 Comments