How to Send Email from the Linux Command Line Using an SMTP Server (with SSMTP)
We want to stay connected to everyone in the global world. In order to accomplish this, email is a widely used way of sending and receiving information. Linux systems also provide command-line tools for sending emails, which can be used to obtain system information, send emails from shell scripts, and so on.
Table of Contents
Linux Command Line
Email is sent as system username@hostname when sent from a Linux terminal. These emails can be blocked or marked as spam by certain SMTP servers. As a result, we need a method that maximizes email delivery to the inbox. We would use this article to set up our server to transfer email from SMTP servers like Gmail, Amazon SES, and others. This article will show you How to Send Email from the Linux Command Line Using an SMTP Server (with SSMTP).
Step 1: Install SSMTP Server
SSMTP service packages can be found in the EPEL repository, so make sure you have the EPEL yum repository configured.
# yum install ssmtp
Step 2: Set up SSMTP
# vim /etc/ssmtp/ssmtp.conf
mailhub=smtp.gmail.com:587 UseSTARTTLS=YES AuthUseremail@example.com AuthPass=XXXXXXXXXXXXXXX TLS_CA_File=/etc/pki/tls/certs/ca-bundle.crt
- mailhub: your SMTP server’s host/ip address and port
- UseSTARTTLS: If the SMTP server uses TLS, set it to Yes; otherwise, set it to No.
- AuthUser: Use your Gmail ID here.
- AuthPass: Use your Gmail ID’s password.
- TLS_CA_File: If you encounter an error such as “send-mail: Cannot open smtp.gmail.com:587,” this will take some time.
Step 3: Send a Test Email
Send a test email to an email address to test the setup. First, write the email in a text file, as follows:
# vim msg.txt
Subject: This is Subject Line Email content line 1 Email content line 2
# ssmtp firstname.lastname@example.org < msg.txt
Let us see if there is something new in your inbox.
Step 4: Make SSMTP the default client.
Set SSMTP as your default mail server so that you can send emails via SSMTP with the mail command.
alternatives --config mta There are 2 programs which provide 'mta'. Selection Command ----------------------------------------------- 1 /usr/sbin/sendmail.ssmtp *+ 2 /usr/sbin/sendmail.sendmail Enter to keep the current selection[+], or type selection number: 1
Verify the changes by following command
sendmail -V sSMTP 2.61 (Not sendmail at all)
44 Best Free Online Movie Streaming Sites
If you searched for the best free online movie streaming sites, then you have reached the right place. Here’s a…