Professional Documents
Culture Documents
Send Gmail
Send Gmail
/bin/sh
#
#
# This script will send an email using a Gmail account through an openssl sessio
n.
#
# Version 1.0
# December 23, 2015
#
#
# Note: you must turn ON "Access for less secure apps" in the Gmail settings:
# https://www.google.com/settings/security/lesssecureapps
# I therefore recommend you create a separate Gmail account just for your router
.
#
#
# Usage: ./sendgmail.sh login password recipient subject message
#
#
# (and some patience... it takes less than 10 seconds)
#
# login
: the Gmail login you created for the router
#
# password : the Gmail password (best to enclose in quotes "" in case there are
any spaces)
#
# recipient : email address of recipient
#
# subject : subject of email (best to enclose in quotation marks "" since any
spaces will
#
be misinterpreted as the start for the next parameter)
#
# message : body of email (enclose in quotation marks "" and do not start any
lines with a dot!).
#
You can pipe a file like this: ./sendgmail.sh ... "$(cat yourfileh
ere)" (you
#
have to use quotes otherwise any space is treated as the next para
meter).
#
You can also include escape characters (like new line \n) by using
$'some\nmessage'
#
as the message parameter (note the dollar sign and single quotes).
#
#
# Examples of usage :
#
# Send a simple message from command line:
# ./sendgmail.sh randomemail@gmail.com secretpassword recipient@gmail.com "Cool
subject" "Nice body (of email)"
#
# Send a message with some new line feeds \n in body:
# ./sendgmail.sh randomemail@gmail.com secretpassword recipient@gmail.com "Cool
subject" $'Nice body\n(of email)'
#
# Send a message from command line but read email body from a text file called "
body.txt":
# ./sendgmail.sh randomemail@gmail.com secretpassword recipient@gmail.com "Cool
subject" "$(cat body.txt)"
#
# And for this one, see notes below for explanation:
# read login passwd <credentials.txt ; ./sendgmail.sh $login $passwd recipient@g