How to send an email from Linux Terminal?!

How to send an email from Linux Terminal?!

ยท

2 min read

As you can see, we are going to send an email from our Ubuntu Terminal. Let's do it then!

We are going to use the ssmtp CLI Utility. It is easily installed by running:

sudo apt install ssmtp

After our SMPT Utility has been installed, we need to do some changes to the /etc/ssmtp/ssmtp.conf configuration file.

Let's open this file using nano:

sudo nano /etc/ssmtp/ssmtp.conf

Make this file like this:

#
# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
# root=postmaster

# The place where the mail goes. The actual machine name is required no
# MX records are consulted. Commonly mailhosts are named mail.domain.com
mailhub=smtp.gmail.com:587

AuthUser=YOUR_EMAIL_HERE
AuthPass=YOUR_APP_PASSWD_HERE
UseTLS=YES
UseSTARTTLS=YES

# Where will the mail seem to come from?
rewriteDomain=gmail.com

# The full hostname
hostname=test

# Are users allowed to set their own From: address?
# YES - Allow the user to specify their own From: address
# NO - Use the system generated From: address
FromLineOverride=YES

One important thing to note here is that you should not use your account's original password for this. Instead you have to make an App Password for this to work.

Head on to this link to setup an app password for your Google Account.

After this, you can easily send emails from your command line!!

ssmpt RECIPIENT_EMAIL_HERE

Hit enter, then type out:

Subject: SUBJECT_FOR_THE_MAIL_HERE

Hit enter, then you can type out the content of your email:

Sample content of the email

Now hit enter, and press Ctrl+D to send the email.

That's it for sending email from your Linux Terminal. Hope it helps!

Connect with me:

๐Ÿ”— LinkedIn: linkedin.com/in/harshit-sharma--

๐Ÿ”— My YouTube Channel: youtube.com/c/CoderBuddy?sub_confirmation=1

๐Ÿ”— GitHub: github.com/harshit-sharma-gits

ย