• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here:Home » Easily Set Up Email with SMTP on Ubuntu Server

By Abhishek Ghosh May 29, 2023 8:15 am Updated on May 29, 2023

Easily Set Up Email with SMTP on Ubuntu Server

Advertisement

It is very easy to use msmtp package, configure a dedicated email account for the server and send email alerts from the server or the web application, such as WordPress. However, for making web applications such as WordPress work, you need to perform a few extra steps which we have not described in this article.

To follow this guide, you need a dedicated email account for this purpose. If you are using paid hosted email for a domain, such as we use for our official emails, avoid using them since there is a remote change of getting the email blacklisted or hacked. You can use an email address such as webserver.yourdomain@gmail.com.

MTA stands for Mail Transport Agent. It is a component which forward and routes the emails using the headers on the email. It communicates with many other components in the SMTP. It can accept emails, forward emails for further routing, and pass the email to the MDA (Mail Delivery Agent).

Advertisement

---

 

How To SMTP on Ubuntu Server With msmtp

 

msmtp is an SMTP client which transmits mail to an SMTP server for further delivery. This is an alternative to /usr/sbin/sendmail. This is a lightweight free software published under GNU GPL license. This is the official site:

Vim
1
https://marlam.de/msmtp/

msmtp-mta creates a symbolic link from /usr/bin/sendmail to /usr/bin/msmtp. So we will need to install three packages:

Vim
1
sudo apt-get install msmtp msmtp-mta mailutils

Normally you will have certificates here:

Vim
1
ls /etc/ssl/certs

If it is absent or empty then run:

Vim
1
sudo apt-get install ca-certificates

Create a log directory and give permission to Apache:

Vim
1
2
3
4
5
6
sudo mkdir -p /var/log/msmtp
sudo touch /var/log/msmtp/msmtp.log
sudo chown www-data:www-data /var/log/msmtp
sudo chown www-data:www-data /var/log/msmtp/msmtp.log
sudo systemctl restart msmtpd.service
sudo systemctl status msmtpd.service

If you use PHP-FPM with MPM Event, then open this file (change the version of PHP on path):

Vim
1
2
3
locate fpm/php.ini
## get the path
nano /etc/php/7.2/fpm/php.ini

Search for the phrase sendmail_path, uncomment it and make it look like the below:

Vim
1
sendmail_path = /usr/bin/msmtp -C /etc/msmtprc

You’ll get example configurations here:

Vim
1
2
sudo updatedb
locate msmtprc

Here are the files:

Vim
1
2
/usr/share/doc/msmtp/examples/msmtprc-system.example
/usr/share/doc/msmtp/examples/msmtprc-user.example

Run cat on them:

Vim
1
2
cat /usr/share/doc/msmtp/examples/msmtprc-user.example
cat /usr/share/doc/msmtp/examples/msmtprc-system.example

and create your settings file:

Vim
1
sudo nano /etc/msmtprc

with this kind of setting, make sure that port 587 is open:

Restart, and reload the required services:

Vim
1
2
3
service php7.2-fpm restart
apachectl configtest
/etc/init.d/apache2 reload

Avoid suddenly running service apache2 restart on a production server, you may face Config variable ${APACHE_RUN_DIR} is not defined error.

Usually, the dedicated servers have additional firewall which we can not see. More than allowing ufw, iptables, fail2ban and configuration on the control panel’s firewall, you need not to do anything. If it fails then open a support ticket, show this guide which you were trying. They will open the port for you.

Now, test the thing with this text file, edit it correctly, and save it as text.txt:

Vim
1
2
3
4
5
6
7
8
9
10
11
12
From: Abhishek Ghosh <username@hotmail.com>
To:   Recipient <your-another-emaile@hotmail.com>
Subject: It Works! Test successful
 
You have successfully set up MSMTP after reading our guide.
 
Consider subscribing to our free newsletter and mobile notification.
 
Regards,
 
Abhishek Ghosh
https://thecustomizewindows.com

Now send it:

Vim
1
cat test.txt | msmtp username@hotmail.com

You’ll get no output on SSH. This is an example email received on inbox:

Easily Set Up Email with SMTP on Ubuntu Server

Also, you can check the log:

Vim
1
cat /var/log/msmtp/msmtp.log

 

How to Use mail Command to Send Email

 

Edit this:

Vim
1
sudo nano /etc/mail.rc

Add this line:

Vim
1
set mta=/usr/bin/msmtp

Create:

Vim
1
nano /etc/aliases

Add :

Vim
1
2
3
your_username: username@hotmail.com
# reference
# https://wiki.archlinux.org/title/Cron#Example_with_msmtp

Now, test it:

Vim
1
echo "Testing msmtp with mail command" | mail -s "Does it Work" your-another-emaile@hotmail.com

It should work. The next guide is about how to configure WordPress so that it can send you an email with this setup.

Facebook Twitter Pinterest

Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to Easily Set Up Email with SMTP on Ubuntu Server

  • Nginx WordPress Installation Guide (All Steps)

    This is a Full Nginx WordPress Installation Guide With All the Steps, Including Some Optimization and Setup Which is Compatible With WordPress DOT ORG Example Settings For Nginx.

  • Join/Merge Multiple Log Files For Big Data Analysis

    Here Are The Ways To Join/Merge Multiple Log Files For Big Data Analysis, Store Them To OpenStack Based Cloud Storage And Delete Old Files.

  • WordPress Multisite on Nginx on Ubuntu 14.04 on HP Cloud

    Here is a Step by Step Guide on Setting Up WordPress Multisite on Nginx on Ubuntu 14.04 on HP Cloud with All Commands and the Configuration.

  • unix Commands to Check Server Logs For Security

    Here is a Basic Guide For the Beginners to Self Manage Cloud Server Instances. Master these unix Commands to Check Server Logs For Security.

performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

Get new posts by email:

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (24.3K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • Hybrid Multi-Cloud Environments Are Becoming UbiquitousJuly 12, 2023
  • Data Protection on the InternetJuly 12, 2023
  • Basics of BJT TransistorJuly 11, 2023
  • What is Confidential Computing?July 11, 2023
  • How a MOSFET WorksJuly 10, 2023
PC users can consult Corrine Chorney for Security.

Want to know more about us?

Read Notability and Mentions & Our Setup.

Copyright © 2023 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy