Last active
May 12, 2017 18:53
-
-
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..
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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: | |
# [email protected] an-user | |
# [email protected] another | |
# [email protected] 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 <[email protected]>' \ | |
-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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
chmod +x or execute:
$ bash send_emails.sh userlist.list