Skip to content

Mailgun driver for itsabot/abot/shared/interface/email

License

Notifications You must be signed in to change notification settings

DaleWebb/mailgun

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mailgun

Mailgun driver for itsabot/abot/shared/interface/email to send and receive emails

Abot Setup

Sign up for Mailgun. For development, you can use your sandbox domain and sandbox API key, given to you when you signup. You'll want to set the following environment variables in your ~/.bash_profile or ~/.bashrc:

export MAILGUN_DOMAIN="REPLACE"
export MAILGUN_API_KEY="REPLACE"

We'll also want to update our environment variables on Heroku, so run the following in your terminal:

heroku config:set MAILGUN_DOMAIN=REPLACE \
MAILGUN_API_KEY=REPLACE

Now we'll add the Mailgun driver. Since we've written a plugin for Mailgun like any other, you can simply add it to your plugins.json like so:

{
    "Name": "abot",
    "Version": "0.1.0",
    "Dependencies": {
        "github.com/itsabot/plugin_onboard": "*",
        "github.com/DaleWebb/mailgun": "*"
    }
}

Then from your terminal run:

abot plugin install

Mailgun Configuration

The Mailgun driver will automatically add a special POST /mailgun route to Abot.

Let's also make sure that Mailgun knows how to communicate with our plugin.

For Mailgun to send your emails to Abot, your Abot will need to be hosted online.

Add a route to your Mailgun account that will POST to our Abot's route every time Mailgun receives an email. There are two ways to do that, either:

  1. Via the Mailgun dashboard and add the filter expression: match_recipient(".*@MAILGUN_DOMAIN") and add the action: `forward("https://MAILGUN_DOMAIN/mailgun/")``.

  2. Via the Terminal, you can execute this command.

curl -s --user 'api:MAILGUN_API_KEY' \
    https://api.mailgun.net/v3/routes \
    -F priority=0 \
    -F description='Sample route' \
    -F expression='match_recipient(".*@MAILGUN_DOMAIN")' \
    -F action='forward("https://MAILGUN_DOMAIN/mailgun/")' \
    -F action='stop()'

##Testing it out

To try it out, let's first create an Abot account through the web interface. Go to your Abot domain (heroku open) and click on Sign Up in the header at the top right.

Once you've signed up, send Abot an email to any-name@MAILGUN_DOMAIN. Sometimes responses via Mailgun take a few seconds, but you should get a reply back shortly.

You can also simulate a Mailgun callback via cURL, if you do not have a online Abot.

curl -H "Content-Type: application/json" -X POST -d '{"stripped-text":"hi", "recipient": "abot@$MAILGUN_DOMAIN", "sender": "[email protected]", "subject": "test"}' https://localhost:4200/mailgun

About

Mailgun driver for itsabot/abot/shared/interface/email

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages