• 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 » Set Up Email with mSMTP on Ubuntu 22.04 Server

By Abhishek Ghosh January 27, 2024 9:05 am Updated on January 27, 2024

Set Up Email with mSMTP on Ubuntu 22.04 Server

Advertisement

This is a sendmail emulator system which delivers email from a local computer to an SMTP server. This method avoids the usage of cloud-based transactional email subscriptions. This is useful if you already using a paid tier of Outlook Gmail or Zoho for your domain. In other words, you’ll get domain-branded, whitelisted email from your server to your mailbox. Normally we need server cron and WordPress to send us emails.

One of our earlier guides on Ubuntu 22.04 Server was on how to set up a Passwordless SSH Login. It is mandatory to follow that guide and create a non-root user and follow this guide. Unless you secure your server, hackers will get access to your email credentials.

There are several ways to configure a Linux server to send email. msmtp is an SMTP client which is free software, published under the GPLv3. MTA stands for Mail Transport Agent. It is a component which forwards 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

---

If you are using servers from VPSDime, then you must not abuse the system for mass emailing. To follow this guide, you need:

  • An Ubuntu 22.04 server running Apache2, PHP (version 7.2 to 8.4), MySQL
  • 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 chance of getting the email blacklisted or hacked. You can use an email address such as webserver.yourdomain@gmail.com. Any email account from Outlook/Hotmail, Yahoo!, Gmail or similar service will work fine.
  • Of course, you must be able to SSH into the server with root privilege.

 

Step 1: Install the Required Packages to Operate msmtp

 

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

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

Now, SSH to your server.

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

Vim
1
2
sudo apt update -y && apt upgrade -y
sudo apt-get install msmtp msmtp-mta mailutils

It will ask whether the wizard will enable App Armour support. Answer NO.

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 permit Apache:

Vim
1
2
3
4
5
6
7
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
# press Q to exit

If you use How to Install Apache MPM Event and PHP-FPM on Ubuntu Server, 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_pathand sendmail_from fields (use ctrl + W in Nano), it will look like this:

Vim
1
2
3
4
5
6
7
8
9
10
11
; http://php.net/sendmail-from
;sendmail_from = me@example.com
 
; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
;sendmail_path =
 
; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail().
;mail.force_extra_parameters =

uncomment it and make it look like the below:

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

Save the file (use ctrl + O in Nano to save, ctrl + X to exit). 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. Now, test the thing with this text file, edit it correctly, and save it as test.txt (run the command nano test.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

Tagged With msmtp subject
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 Set Up Email with mSMTP on Ubuntu 22.04 Server

  • Easily Set Up Email with SMTP on Ubuntu Server

    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. […]

  • 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.

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…

 

vpsdime

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

  • Cloud-Powered Play: How Streaming Tech is Reshaping Online GamesSeptember 3, 2025
  • How to Use Transcribed Texts for MarketingAugust 14, 2025
  • nRF7002 DK vs ESP32 – A Technical Comparison for Wireless IoT DesignJune 18, 2025
  • Principles of Non-Invasive Blood Glucose Measurement By Near Infrared (NIR)June 11, 2025
  • Continuous Non-Invasive Blood Glucose Measurements: Present Situation (May 2025)May 23, 2025
PC users can consult Corrine Chorney for Security.

Want to know more about us?

Read Notability and Mentions & Our Setup.

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

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