Methods to set up Sendmail on Ubuntu 22.04 and configure it for sending emails utilizing a e mail server which routes or relays the mail supply.
Sendmail is a opensource Mail Switch Agent (MTA) which is used to route e mail utilizing server or through the use of shell instructions. It’s also possible to configure SMTP utilizing Sendmail.
On this information you will discover ways to set up and setup Sendmail on Ubuntu. Additionally you’ll setup SMTP and configure it with PHP.
Replace Server Packages
SSH inside your server and replace the packages to it’s newest model.
sudo apt replace sudo apt improve
Set up Sendmail
Sendmail is on the market within the ubuntu repository, so you may straight set up utilizing apt set up
command.
sudo apt set up sendmail
Configure Hostname
Edit the /and many others/hosts
file and add your hostname.
sudo nano /and many others/hosts
On the road beginning with 127.0.0.1
, add the hostname
to the top because it appears beneath. This must be on a single line.
127.0.0.1 localhost hostname
Configure SMTP
Create new listing inside /and many others/mail
for SMTP configurations.
sudo mkdir /and many others/mail/authinfo
Setup appropriate permissions.
sudo chmod -R 700 /and many others/mail/authinfo
Create a brand new file in your SMTP authentication contained in the newly created listing.
cd /and many others/mail/authinfo sudo nano smtp-auth
Paste the next line and change the email-address together with your login e mail and password together with your password.
AuthInfo: "U:root" "I:email-address" "P:password"
Hit CRTL + X
adopted by Y
and ENTER
to avoid wasting and exit the file.
Create a hash database map for the above created authentication.
sudo makemap hash smtp-auth < smtp-auth
Configure SMTP
Navigate to the sendmail configuration listing and edit the sendmail.mc
file.
cd /and many others/mail sudo nano sendmail.mc
Add the beneath configurations proper after the MAILER _DEFINITIONS line.
Change smtp-host
together with your SMTP hostname.
outline(`SMART_HOST',`[smtp-host]')dnl outline(`RELAY_MAILER_ARGS', `TCP $h 587')dnl outline(`ESMTP_MAILER_ARGS', `TCP $h 587')dnl outline(`confAUTH_OPTIONS', `A p')dnl TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl outline(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl FEATURE(`authinfo',`hash -o /and many others/mail/authinfo/smtp-auth.db')dnl
The configuration ought to appear to be the identical because the beneath screenshot.
Now save the file and exit the editor.
Rebuild Sendmail Configuration
As soon as the configuration is completed it’s essential rebuild the Sendmail configuration utilizing the make
command.
cd /and many others/mail make
As soon as the configuration is rebuilt it’s essential restart Sendmail
Restart Sendmail
Restart Sendmail utilizing the next command.
sudo /and many others/init.d/sendmail restart
Now you may ship emails utilizing SMTP.
Further Configurations
Configuration with PHP
To make use of Sendmail with PHP it’s essential advert sendmail path in your php.ini
file.
sudo nano /and many others/php/model/fpm-or-apache2/php.ini
To the underside of the file add the next.
sendmail_path= /usr/sbin/sendmail -t -i
Restart Apache or PHP-FPM for the adjustments to take impact.
sudo service apache2 restart or sudo service php8.1-fpm restart
Sendmail SMTP Configuration with out Auth
Incase if in case you have whitelisted your server IP for SMTP and you’ll ship emails with out authentication you may observe the beneath technique.
You don’t must create the smtp-auth
file that we created above.
You’ll be able to straight edit the sendmail.mc
file and make the next adjustments.
cd /and many others/mail sudo nano sendmail.mc
Add the beneath configurations to the final.
Change smtp-host
together with your SMTP hostname.
outline(`SMART_HOST',`smtp-host')dnl
outline(`RELAY_MAILER', `esmtp')dnl
outline(`RELAY_MAILER_ARGS', `TCP $h 587')dnl
Save the file, rebuild configuration and restart Sendmail.
cd /and many others/mail make sudo /and many others/init.d/sendmail restart
Put together your self for a task working as an Information Technology Professional with Linux working system
Conclusion
Now you will have discovered methods to set up and configure Sendmail to relay utilizing SMTP on Ubuntu 22.04.
Thanks in your time. When you face any downside or any suggestions, please depart a remark beneath.