Skip to content

Instantly share code, notes, and snippets.

@avcaliani
Last active May 2, 2020 03:15
Show Gist options
  • Save avcaliani/5c8645ab2a625a2d42358d56beb9df58 to your computer and use it in GitHub Desktop.
Save avcaliani/5c8645ab2a625a2d42358d56beb9df58 to your computer and use it in GitHub Desktop.
#code #bash #mailjet

๐Ÿ“จ Mailjet

By Anthony Vilarim Caliani

# # #

This is an example of working with Mailjet API.
But, before you try it you must edit email.sh to set some variables...
By the way, all these data can be found at your page on Mailjet

APP_EMAIL="your-email@mailjet.com"
APP_NAME="Your Name"
API_KEY="********************************"
API_SECRET="********************************"

Well, now that you have set the variables... Let's rock!

./email.sh 'my-receiver@mailjet.com'

Finally... SURPRISE ๐Ÿฅณ๐Ÿป๐Ÿค˜

z-email

Related Links

#!/bin/bash
# @script email.sh
# @author Anthony Vilarim Caliani
# @contact github.com/avcaliani
#
# @description
# Script to send e-mails via Mailjet API
#
# @params
# 01 - Receiver e-mail
#
# @usage
# ./email.sh 'my-receiver@mailjet.com'
#
APP_EMAIL="your-email@mailjet.com"
APP_NAME="Your Name"
API_KEY="********************************"
API_SECRET="********************************"
# ___ _ _
# | __| _ _ _ __| |_(_)___ _ _ ___
# | _| || | ' \/ _| _| / _ \ ' \(_-<
# |_| \_,_|_||_\__|\__|_\___/_||_/__/
get_emoji() {
IFS=' ' # Emojis must be separated by white spaces
read -ra emojis <<< $(cat emojis.txt)
size=${#emojis[@]}
index=$((${RANDOM} % ${size}))
echo "${emojis[${index}]}"
}
parse_content() {
template=$(cat template.html | sed -e "s/@@EMOJI@@/$(get_emoji)/g")
echo $( echo $template | sed -e "s/\"/\\\\\"/g")
}
# ___
# | _ \_ _ _ _
# | / || | ' \
# |_|_\\_,_|_||_|
if [[ -z "$1" ]]; then
echo "Ops! Something is missing..."
echo "Before sending you must define the receiver e-mail."
exit 1
fi
curl -s \
-X POST \
--user "${API_KEY}:${API_SECRET}" \
'https://api.mailjet.com/v3.1/send' \
-H 'Content-Type: application/json' \
-d "{
\"Messages\":[{
\"From\" : { \"Email\": \"${APP_EMAIL}\", \"Name\": \"${APP_NAME}\" },
\"To\" : [ { \"Email\": \"$1\" } ],
\"Subject\" : \"Surprise!\",
\"HTMLPart\": \"$(parse_content)\",
\"CustomID\": \"$(uuidgen)\"
}]
}" | json_pp
exit 0
๐Ÿ˜€ ๐Ÿ˜ ๐Ÿ˜‚ ๐Ÿคฃ ๐Ÿ˜ƒ ๐Ÿ˜„ ๐Ÿ˜… ๐Ÿ˜† ๐Ÿ˜‰ ๐Ÿ˜Š ๐Ÿ˜‹ ๐Ÿ˜Ž ๐Ÿ˜ ๐Ÿ˜˜ ๐Ÿฅฐ ๐Ÿ˜— ๐Ÿ˜™ ๐Ÿ˜š โ˜บ๏ธ ๐Ÿ™‚ ๐Ÿค— ๐Ÿคฉ ๐Ÿค” ๐Ÿคจ ๐Ÿ˜ ๐Ÿ˜‘ ๐Ÿ˜ถ ๐Ÿ™„ ๐Ÿ˜ ๐Ÿ˜ฃ ๐Ÿ˜ฅ ๐Ÿ˜ฎ ๐Ÿค ๐Ÿ˜ฏ ๐Ÿ˜ช ๐Ÿ˜ซ ๐Ÿ˜ด ๐Ÿ˜Œ ๐Ÿ˜› ๐Ÿ˜œ ๐Ÿ˜ ๐Ÿคค ๐Ÿ˜’ ๐Ÿ˜“ ๐Ÿ˜” ๐Ÿ˜• ๐Ÿ™ƒ ๐Ÿค‘ ๐Ÿ˜ฒ โ˜น๏ธ ๐Ÿ™ ๐Ÿ˜– ๐Ÿ˜ž ๐Ÿ˜Ÿ ๐Ÿ˜ค ๐Ÿ˜ข ๐Ÿ˜ญ ๐Ÿ˜ฆ ๐Ÿ˜ง ๐Ÿ˜จ ๐Ÿ˜ฉ ๐Ÿคฏ ๐Ÿ˜ฌ ๐Ÿ˜ฐ ๐Ÿ˜ฑ ๐Ÿฅต ๐Ÿฅถ ๐Ÿ˜ณ ๐Ÿคช ๐Ÿ˜ต ๐Ÿ˜ก ๐Ÿ˜  ๐Ÿคฌ ๐Ÿ˜ท ๐Ÿค’ ๐Ÿค• ๐Ÿคข ๐Ÿคฎ ๐Ÿคง ๐Ÿ˜‡ ๐Ÿค  ๐Ÿคก ๐Ÿฅณ ๐Ÿฅด ๐Ÿฅบ ๐Ÿคฅ ๐Ÿคซ ๐Ÿคญ ๐Ÿง ๐Ÿค“ ๐Ÿ˜ˆ ๐Ÿ‘ฟ ๐Ÿ‘น ๐Ÿ‘บ ๐Ÿ’€ ๐Ÿ‘ป ๐Ÿ‘ฝ ๐Ÿค– ๐Ÿ’ฉ ๐Ÿ˜บ ๐Ÿ˜ธ ๐Ÿ˜น ๐Ÿ˜ป ๐Ÿ˜ผ ๐Ÿ˜ฝ ๐Ÿ™€ ๐Ÿ˜ฟ ๐Ÿ˜พ
<!DOCTYPE html>
<html>
<head>
<style>
body { font-family: Arial, Helvetica, sans-serif; }
h1 { text-align: center; font-size: 5em; margin: 0; }
h3 { text-align: center; margin-top: 3em; }
p { text-align: center; font-size: smaller; color: gray; margin-top: 20px; }
a { text-decoration: none; color: dodgerblue; }
span { color: hotpink; }
</style>
</head>
<body>
<h3>Here it is a very cool emoji for you...</h3>
<h1>@@EMOJI@@</h1>
<p>
Message created with <span>โค๏ธŽ</span> by <a href="https://github.com/avcaliani">@avcaliani</a>
</p>
</body>
</html>
@avcaliani
Copy link
Author

avcaliani commented Apr 15, 2020

Just a backup XD
z-email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment