Effortless Email Sending on Linux: A Step-by-Step Project Guide

IEEE_TEMS BLOGS
3 min readAug 24, 2023

--

“Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom.” — Clifford Stoll

INTRODUCTION

Emails have been an essential part of communication. Today in this blog we are going to know how to send emails without ever going to your browser or Gmail app by just using some cool command lines on Linux. you may ask But why to do all this for now I will say maybe just to look like a hacker.

SETTING UP THE THINGS

Later in the process, we are going to require an SMTP server to send emails. In this project, we are going to use Gmail servers as it is widely used. For this, we are going to set up an application password for our Google account.

  • open setting go to Google account.
  • In the Security tab if 2-step verification is off turn it on.
  • At the bottom of 2-step, there will be an option for app passwords Set up a new application password.
  • A password will come on the screen note it up as it will be not available we are going to use that later.
  • To send emails we are going to use a Linux package S-nail to install the run command sudo apt-get install s-nail in your terminal.

CODE

Now let’s start the project go to your Linux terminal and run the command nano filename.sh

to open a text editor and write the following shell script code.

#!/bin/bash
read -p "enter mail id:" mail
read -p "enter subject:" subject
read -p "enter message:" message

echo "$message" | s-nail -r "yourmail" -s "$subject" -S smtp="smtp.gmail.com:587" -S smtp-use-starttls -S smtp-auth=login -S smtp-auth-user="your gmail id" -S smtp-auth-password="app password " -S ssl-verify=ignore $mail

Let’s break down the code-

  • The initial three lines are used to take the input from the user.
  • echo is used to print anything.
  • we are using the s-nail package for sending emails.
  • the message is the body of our email,-r for the sender email,-s is used for the subject,-S and is used to specify other settings we are using to set up our SMTP server.
  • Press ctrl+o & ctrl+x to save and exit the editor.

CONCLUSION

Ok if you finished reading this and did all the things mentioned you are all set to send emails. Just run the shell script we made using sudo chmod 777 file_name.sh & ./filename.sh enter the required details press join and enjoy the joy and happiness of sending a mail just using command lines.

Happy Coding :)

Thank you for being here!! give it a thumbs up, drop a comment, and share if you find it even a little helpful.

ABOUT THE AUTHOR

Hey there, I’m Akshat Agarwal, a student at VIT. I’m an avid reader and writing enthusiast — it’s through writing that I indeed find myself and connect with others. Music is my jam, and I thrive on collaborating and initiating projects. Writing, essentially, allows me to capture moments, explore different angles, and leave a lasting impact. Join me on this journey of learning and growth at VIT, one word at a time.

--

--

IEEE_TEMS BLOGS
IEEE_TEMS BLOGS

Written by IEEE_TEMS BLOGS

IEEE_TEMS, a chapter of VIT UNIV, before we tell about us STOP! Make your fingers join forces with your mind to work hard.Let’s go to the glassy world of techs

Responses (1)