Coder Social home page Coder Social logo

sending-emails-through-cli-'s Introduction

sending-emails-through-CLI-

Email notifications are necessary to send details about the health of the system or to send any logs and much more. To send automatic mail through CLI follow the below steps: There are various tools available in market to send emails such as

  • mailx
  • ssmtp

We are using a GMAIL SSMTP to send emails.

#prerequisites

  • You should have Linux as your operating system.
  • Turn on access to less secure apps here

Follow along with me

  yum install ssmtp
  cd /etc/ssmtp

Now edit the ssmtp file present in this ssmtp directory. You can use any editor. For simplicity I am using vi editor here.

vi ssmtp.conf

Add these variables in this file.

mailhub=smtp.gmail.com:587
useSTARTTLS=YES
[email protected]
AuthPass=password-here
TLS_CA_File=/etc/pki/tls/certs/ca-bundle.crt

Put the appropriate values for AuthUser and AuthPass mailhub is the domain name of the third party service. If you want to use any other service you can replace this domain name. Here we have used gmail.

Now we have successfully configured. You can use various ways to send mails

  1. ###A very easiest way to send mails
echo "Greetings from Terminal!!!" | sudo ssmtp [email protected]

  1. You can use the same ssmtp to send mail from a shell script too. For that, open your preferred editor and create a shell script file with name saymail.shand copy-paste the below code:
#!/bin/sh  
SUBJECT="Test Subject"
TO="[email protected]"
MESSAGE="Hey There! This is a test mail"

echo $MESSAGE | sudo ssmtp $TO

Make sure you have set the right permission access to your script file. If not, here is the command to set the permission:

sudo chmod 755 mail.sh 

sudo ./mail.sh

Hope now you're able to send mails using the shell script too.

<! Happy Coding !>

sending-emails-through-cli-'s People

Contributors

aliana17 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.