Mailgun's website is stupid, so this executable gem lets you query events from commandline.
Install:
gem install mailqun
Set the following env variables:
MAILGUN_DOMAIN=domain.com
MAILGUN_SECRET=key-lalala.domain.secret
And now:
$> mailqun -h
Usage: mailqun [options]
Common options:
-f, --from [FROM] Address of the sender
-t, --to [TO] Address of the receiver
-s, --subject [SUBJECT] Subject of mail
-l, --limit [LIMIT] Limit on number of results
--tags [TAG] Value in X-Mailgun-Tag header
-e, --event [EVENT] Event being queried
Bounce options:
--bounces Add this option to query bounces instead of events
-a, --address [ADDRESS] Bounced address, used with --bounces
--delete [ADDRESS] Delete address from bounces, used with --bounces
View options:
--view-body [URL] Mailgun storage URL to fetch email body from
Fetch one delivery event for a mail addressed to [email protected]
with the word 'potato' in the subject
$> mailqun --to [email protected] --event delivered --subject potato --limit 1
Fetch ten acceptance events for mails sent by [email protected]
with the tag 'cool'
$> mailqun -f [email protected] -e accepted --tags cool --limit 10
Check if [email protected]
is on the bounce list
$> mailqun --bounces -l 2 -a [email protected]
View body of email stored in some Mailgun url
$> mailqun --view-body "https://sw.api.mailgun.net/v3/domains/domain.com/messages/uglyhash"
# => Saves mail in a .html file and opens using default program
I am aware that this script is a mess. It was born as a result of frustration arising from seeing Mailgun's "Don't get angry" page a few times too many. I would welcome improvements, both features and design changes. Bug reports and pull requests are welcome on the GitHub repo. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The gem is available as open source under the terms of the MIT License.