Cloudbooklet
  • News
  • Artificial Intelligence
  • Applications
  • Linux
No Result
View All Result
Cloudbooklet
  • News
  • Artificial Intelligence
  • Applications
  • Linux
No Result
View All Result
Cloudbooklet
No Result
View All Result
Home Linux

How to Install and Setup Sendmail on Ubuntu

by Cloudbooklet
2 years ago
in Linux
Install And Setup Sendmail
ShareTweetSendShare
Readers like you help support Cloudbooklet. When you make a purchase using links on our site, we may earn an affiliate commission.

How to install and configure Sendmail on Ubuntu for sending emails using a email server which routes or relays the mail delivery. Sendmail is a opensource Mail Transfer Agent (MTA) which is used to route email using server or by using shell commands. You can also configure SMTP using Sendmail. In this guide you are […]

ADVERTISEMENT

How to install and configure Sendmail on Ubuntu for sending emails using a email server which routes or relays the mail delivery.

Sendmail is a opensource Mail Transfer Agent (MTA) which is used to route email using server or by using shell commands. You can also configure SMTP using Sendmail.

In this guide you are going to learn how to install and setup Sendmail on Ubuntu. Also you will setup SMTP and configure it with PHP.

ADVERTISEMENT

Update Server Packages

SSH inside your server and update the packages to it’s latest version.

You might also like

&Quot; Systemd Service On Linux

How to Create a New systemd Service on Linux: A Step-by-Step Guide

3 months ago
List Groups In Linux

How to List Groups in Linux: A Guide for Beginners

3 months ago
sudo apt update
sudo apt upgrade

Install Sendmail

Sendmail is available in the ubuntu repository, so you can directly install using apt install command.

sudo apt install sendmail

Configure Hostname

Edit the /etc/hosts file and add your hostname.

ADVERTISEMENT
sudo nano /etc/hosts

On the line starting with 127.0.0.1, add the hostname to the end as it looks below. This should be on a single line.

127.0.0.1 localhost hostname

Configure SMTP

Create new directory inside /etc/mail for SMTP configurations.

ADVERTISEMENT
sudo mkdir /etc/mail/authinfo

Setup correct permissions.

sudo chmod -R 700 /etc/mail/authinfo

Create a new file for your SMTP authentication inside the newly created directory.

ADVERTISEMENT
cd /etc/mail/authinfo
sudo nano smtp-auth

Paste the following line and replace the email-address with your login email and password with your password.

AuthInfo: "U:root" "I:email-address" "P:password"

Hit CRTL + X followed by Y and ENTER to save and exit the file.

ADVERTISEMENT

Create a hash database map for the above created authentication.

sudo makemap hash smtp-auth < smtp-auth

Configure SMTP

Navigate to the sendmail configuration directory and edit the sendmail.mc file.

cd /etc/mail
sudo nano sendmail.mc

Add the below configurations right after the MAILER _DEFINITIONS line.

Replace smtp-host with your SMTP hostname.

define(`SMART_HOST',`[smtp-host]')dnl
define(`RELAY_MAILER_ARGS', `TCP $h 587')dnl
define(`ESMTP_MAILER_ARGS', `TCP $h 587')dnl
define(`confAUTH_OPTIONS', `A p')dnl
TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
FEATURE(`authinfo',`hash -o /etc/mail/authinfo/smtp-auth.db')dnl

The configuration should look like the same as the below screenshot.

Smtp Configuration
How to Install and Setup Sendmail on Ubuntu 1

Now save the file and exit the editor.

Rebuild Sendmail Configuration

Once the configuration is done you need to rebuild the Sendmail configuration using the make command.

cd /etc/mail
make

Once the configuration is rebuilt you need to restart Sendmail

Restart Sendmail

Restart Sendmail using the following command.

sudo /etc/init.d/sendmail restart

Now you can send emails using SMTP.

Additional Configurations

Configuration with PHP

To use Sendmail with PHP you need to ad sendmail path in your php.ini file.

sudo nano /etc/php/version/fpm-or-apache2/php.ini

To the bottom of the file add the following.

sendmail_path= /usr/sbin/sendmail -t -i

Restart Apache or PHP-FPM for the changes to take effect.

sudo service apache2 restart
or
sudo service php8.0-fpm restart

Sendmail SMTP Configuration without Auth

Incase if you have whitelisted your server IP for SMTP and you can send emails without authentication you can follow the below method.

You don’t need to create the smtp-auth file that we created above.

You can directly edit the sendmail.mc file and make the following changes.

cd /etc/mail
sudo nano sendmail.mc

Add the below configurations to the last.

Replace smtp-host with your SMTP hostname.

define(`SMART_HOST',`smtp-host')dnl
define(`RELAY_MAILER', `esmtp')dnl
define(`RELAY_MAILER_ARGS', `TCP $h 587')dnl

Save the file, rebuild configuration and restart Sendmail.

cd /etc/mail
make
sudo /etc/init.d/sendmail restart

Conclusion

Now you have learned how to install and configure Sendmail to relay using SMTP on Ubuntu.

Thanks for your time. If you face any problem or any feedback, please leave a comment below.

Tags: EmailPHPUbuntu
Share26Tweet16SendShare
Cloudbooklet

Cloudbooklet

Comments 2

  1. Avatar Of Max Max says:
    10 months ago

    Thanks, excellent work. That was very helpful.

    Reply
  2. Avatar Of Barry Marshall Barry Marshall says:
    11 months ago

    Hi, I’m no expert but this seems very complicated with high level chmod issues which it is taking me hours to figure out. Especially why “chmod 700” leaves a directory which I then cannot cd into. In the end I gave up and started looking elsewhere, after restoring the file to the defaults.

    Reply

Leave a Reply Cancel reply

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

Related Posts

Hostname In Linux

How to Modify the Hostname in Linux

3 months ago
Linux Systems

Linux systems Hacked with OpenSSH Malware

3 months ago
Install Iptables On Ubuntu

How to Install Iptables on Linux

3 months ago
Open Port In Linux

How to Open Port in Linux: Simple Step-by-Step Guide

3 months ago

Follow Us

Trending Articles

Validator Ai

Validator AI: The AI Powered Business Idea Validator

September 20, 2023

10 Best AI Prompts for Writers to Improve Website SEO

Amazon Prime Big Deal Days 2023: Best Deals

7 Best Lyric Video Maker Software for Music Lovers

Microsoft Unveils New Disc-Less Xbox Series X with Lift-to-Wake Controller

10 Best Minecraft Server Hosting Providers in 2023

Popular Articles

Candy Ai

Candy AI: A Revolutionary Way to Interact with AI Characters

September 15, 2023

7 Best Onlyfans Video Downloaders – Chrome Extensions, Apps, Websites

How to Use Hulu Bug Tracker to Improve Your Streaming Experience

Best 10 Instagram Video Downloader Apps and Websites for 2023

9 Best AI Story Generators to Unleash Your Creativity

6 Best AI Cover Song Generators for Free Online

Subscribe Now

loader

Subscribe to our mailing list to receives daily updates!

Email Address*

Name

Cloudbooklet Logo

Welcome to our technology blog, where we explore the latest advancements in the field of artificial intelligence (AI) and how they are revolutionizing cloud computing. In this blog, we dive into the powerful capabilities of cloud platforms like Google Cloud Platform (GCP), Amazon Web Services (AWS), and Microsoft Azure, and how they are accelerating the adoption and deployment of AI solutions across various industries. Join us on this exciting journey as we explore the endless possibilities of AI and cloud computing.

  • About
  • Contact
  • Disclaimer
  • Privacy Policy

Cloudbooklet © 2023 All rights reserved.

No Result
View All Result
  • News
  • Artificial Intelligence
  • Applications
  • Linux

Cloudbooklet © 2023 All rights reserved.