Skip to content

Instantly share code, notes, and snippets.

@sh4t
Last active May 12, 2017 18:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sh4t/24caf59d5cadab7cdff9 to your computer and use it in GitHub Desktop.
Save sh4t/24caf59d5cadab7cdff9 to your computer and use it in GitHub Desktop.
Have a file of your users' name and email address laying around that you need to shoot an email to? I did and didn't want to leverage my server's SENDMAIL, etc so I just use mailgun..
#!/bin/bash
#
# Changed a few things up from my original version I am using
# but thought others might want to have an easy way to send
# emails to users using mailgun via bash..
#
# be sure to replace the FROM field, subject, content, etc
# just read the script and follow-along and modify accordingly.
#
# the contents of the file I am reading are email username:
# someone@something.tld an-user
# another@there.tld another
# where@there.tld user3
filename="$1"
apikey="api:key-1234abcd5678efghijklmnop" #your mailgun api key
domain="shat.io"
while read -a line
do
email=${line[0]}
username=${line[1]}
curl -s --user "${apikey}" \
https://api.mailgun.net/v3/${domain}/messages \
-F from='shat <shat@shat.io>' \
-F to="${username} <${email}>" \
-F subject='Put a real subject here homie..' \
-F text='Hello there,
Shat here, showing you how to send some emails using mailgun.
Feel free to use this example!
Kind regards,
Shat' > /dev/null
echo "queued email to user: ${username} at ${email}"
sleep 0.5 # I throttle, just because.
done < "$filename"
@sh4t
Copy link
Author

sh4t commented Nov 7, 2015

chmod +x or execute:
$ bash send_emails.sh userlist.list

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