Friday, August 12, 2022
No Result
View All Result
Xdatechs Network
  • Home
  • Best Software
  • Linux
  • E-Health
  • Installations
  • Windows
  • Web Hosting
  • Android
  • Home
  • Best Software
  • Linux
  • E-Health
  • Installations
  • Windows
  • Web Hosting
  • Android
No Result
View All Result
Xdatechs Network
No Result
View All Result
Home Linux

How to send one-liner emails from Linux/Ubuntu terminal

by Xdatechs Network
in Linux
How to send one-liner emails from Linux/Ubuntu terminal
25
SHARES
275
VIEWS
Share on FacebookShare on Twitter

In this short tutorial, you will learn how to send one-liner emails using sSMTP from your Linux Ubuntu/Debian terminal. But why on earth would we want to send Emails from the terminal ? Well there could be many reasons. For instance you would want to build an application which sends Emails … You will also be able to attach files to the Email.

Table of Contents

  • What is sSMTP?
  • sSMTP Installation
  • Configuring sSMTP
  • Sending an email
  • Sending a file as an attachment
  • Conclusion :

What is sSMTP?

Before introducing sSMTP, let’s first mention the SMTP protocol. The Simple Mail Transfer Protocol (SMTP) is a protocol used to send and receive emails. Every time you send an email using for instance Gmail, Yahoo and the like, this protocol or service is invoked. Gmail for example uses smtp.gmail.com as their smtp server in order to allow users to access their Email service from other clients.

SSMTP is a simple and lightweight MTA (mail transfer agent) that is used to deliver mails from a machine to a mail hub (that is, SMTP server). It is a client program that forwards your mail to the vendor’s SMTP server which reroutes it to the recipient’s email vendor before sending it to the recipient.

sSMTP Installation

Open up your terminal in order to Install ssmtp using the commands below:

sudo apt-get update

This is to update your repository index of packages. Now issue the command below to install the SMTP client, .i.e. sSMTP :

sudo apt-get install ssmtp

word image 1

Hit Y when prompted.

Configuring sSMTP

In order to configure SSMTP, edit the /etc/ssmtp/ssmtp.conf in your preferred text editor and insert the following lines :

root=your_email@gmail.com
mailhub=smtp.gmail.com:465
FromLineOverride=YES
AuthUser=your_email@gmail.com
AuthPass=your_password
UseTLS=YES

word image 2

Save and exit. Make sure to assign the right permissions to this file since it contains your password or otherwise you may want to create a new email @ gmail for the sole purpose of sending emails from the terminal.

Read: How to tweet from the Linux Command Line

Sending an email

Now we are ready to send an email. To do this, run the command below :

echo “your text” | ssmtp your_receiver@gmail.com

word image 3

Linux send email command

Or you can also use :

printf “your text” | ssmtp receiver@gmail.com

If like me , you get the error shown below :

word image 4

Ubuntu send mail

The error above is mostly likely due to you not having allowed access to less secure apps on your gmail account. You would have also received a notification from gmail related to this. This security setting can be modified through the following link:

https://myaccount.google.com/lesssecureapps

Once you have done this, you will get a notification (probably by phone if not by email). Once you enable the change above, gmail will then allow access to less secure apps.

Now try again to send the email from your terminal and this time it will go though.

Sending a file as an attachment

In order to send an attachment file, you would first to install mpack:

sudo apt-get install mpack

word image 5

Now run the command below :

mpack -s “your text” /your/file/path/here abc@domain.com

word image 6

If you receive this error then you may want to refer to the previous section.

Read: How to display Images in the command line in Linux/Ubuntu 

Conclusion :

Sending emails from the command line can be useful when you need a shell script to send emails manually and automatically. You have seen how to use sSmtp to send one-liner emails as well as how to attach a file using mpack. If you have other methods that enable users to send email, do not hesitate to mention them in the comments section.


If you like the content, we would appreciate your support by buying us a coffee. Thank you so much for your visit and support.

 

Total
0
Shares
Share 0
Tweet 0
Pin it 0
Share 0
Xdatechs Network

Xdatechs Network

Related Posts

How to Block an IP address on a Linux server

How to Block an IP address on a Linux server

by Xdatechs Network
August 11, 2022
0

NOTE: The actual contents and opinions are the sole views of the author who maintains editorial independence.If you’re running...

Guide to Linux Ubuntu/Debian log files for beginners

Guide to Linux Ubuntu/Debian log files for beginners

by Xdatechs Network
August 11, 2022
0

Updated – Ubuntu logs system events into the log files in order to help administrators maintain, analyze and diagnose...

The Most Productive Linux Setup for Photographers

The Most Productive Linux Setup for Photographers

by Xdatechs Network
August 11, 2022
0

For professional photographers, open source software like Linux is just what they need for processing images and keeping their...

The structure of Linux operating system

by Xdatechs Network
August 11, 2022
0

We assume that the reader is familiar with Linux as a user and also, possibly, as a system administrator,...

Thinking About Using Linux Hosting? Here’s What You Need To Know Before Committing

Thinking About Using Linux Hosting? Here’s What You Need To Know Before Committing

by Xdatechs Network
August 11, 2022
0

When you’re choosing a hosting provider, you have a choice, broadly, between a Windows-based or a Linux-based server; the...

How to run Windows software on Linux

How to run Windows software on Linux

by Xdatechs Network
August 11, 2022
0

In this article you will learn how to run windows applications on Linux/Ubuntu 18.04 using Wine and other alternatives....

0 0 votes
Article Rating
Subscribe
Login
Notify of
guest
guest
0 Comments
Inline Feedbacks
View all comments

Support

  • Contact
  • Disclaimer
  • Home
  • Privacy Policy
  • Terms And Conditions

Categories

  • Android
  • Best Software
  • E-Health
  • Installations
  • Linux
  • Web Hosting
  • Windows

More News

  • Three Pieces of Advice for Revamping Your Virtual Meetings
    Three Pieces of Advice for Revamping Your Virtual Meetings
  • How to Build an App from Scratch A Beginner s Guide
    How to Build an App from Scratch: A Beginner’s Guide
  • Home
  • Privacy Policy
  • Contact
  • Disclaimer
  • Terms And Conditions

© 2022 Xdatechs Network - Free Website Builder

No Result
View All Result
  • Best Software
  • E-Health
  • Linux
  • Installations
  • Web Hosting
  • Windows
  • Android
wpDiscuz
0
0
Would love your thoughts, please comment.x
()
x
| Reply