Sending Emails

Webhook Relay provides a Mailgun package to easily send emails on various events.

Prerequisites:

  • Mailgun account (provides generous tier)

Webhook Relay provides a helper package mailgun that can send emails. To start sending emails, create a new Function and just import ‘mailgun’ package. This function will need API key and domain:

-- Import Mailgun helper package
local mailgun = require('mailgun')

local domain = cfg:GetValue('domain')
local api_key = cfg:GetValue('api_key')

-- mailgun.initialize('domain', 'api-key', 'region (us/eu)')
err = mailgun.initialize(domain, api_key, 'us')
if err then error(err) end

-- mailgun.send('sender@foo.com', 'subject', 'body-here', 'recipient@foo.com')
err = mailgun.send('your-email@example.com', 'test subject', 'test body', 'john@example.com')
if err then error(err) end

Then, you will need to enter your API key from the API keys page and set the as config variables for your function. You can find more details on how to find your API keys in Mailgun here.

Last updated