mailgunUser Guide


Mailgun is a simple Fantom API wrapper for the Mailgun email service.


mailgun := Mailgun
  it.privApiKey = "key-3ax6xnjp29jd6fds4gc373sgvjxteol0"
  it.pubApiKey = "pubkey-aba038xlkaj444a898akjzlsoo"
  it.domain = ""


See full send documentation.

  "from": "",
  "to": ",",
  "subject": "Hey There!",
  "text": "Hi :)"

Or use an Email instance:

email := Email
  from = ""
  to = [","]
  subject = "Hey There!"
  body = TextPart { text = "Hi :)" }


See full documentation.

mailgun.unsubscribe                            // get unsubscribe table
mailgun.addUnsubscribe("")     // add address to unsub table
mailgun.getUnsubscribe("")     // get all unsub entries for address
mailgun.removeUnsubscribe("")  // remove all unsub entries for address

// add with tags
mailgun.addUnsubscribe("", "someTag")

Spam Complaints

See full documentation.

mailgun.complaints                           // get complaints table
mailgun.addComplaint("")     // add address to complaints table
mailgun.getComplaint("")     // get complaints entry for address
mailgun.removeComplaint("")  // remove address from complaints table


See full documentation.

mailgun.bounces                           // get bounces table
mailgun.addBounce("")     // add address to bounce table
mailgun.getBounce("")     // get bounce entry for address
mailgun.removeBounce("")  // remove address from bounce table

// add with specific error code and message
mailgun.addBounce("", 551, "The recipient is not local to the server.")


See full documentation  // retrieve events for given params

// get list of all delivered events on the day of 2017-07-01["event":"delivered"], Date(2017-07-01), Date(2017-07-01))

Note that events in particular may be paged. See Paging for more details on iterating paged results.

Email Validation

Email validation requires a pubApiKey to be configured. See full validation documentation.

mailgun.isValidAddres("")     // true or false
mailgun.validateAddress("")   // get full Mailgun validation response as a map


Certain API calls return "pages" of results. For example, the events API works by returning pages of events. Paging information is only available in the first and last entry of the item list. You can page through results by passing either the first or last item to one of the following methods:


// request the initial page of events
events :=["event":"delivered"], Date(2017-07-01), Date(2017-07-01))

// loop until current event list is empty
while (!events.isEmpty)
  events.each |event| { ... }              // process event
  events = mailgun.pageNext(events.last)   // retrieve next page

Everything Else

Not every API has first-class support yet. And just in case Mailgun adds new APIs that are't yet implemented here, you can drop down and use the invoke method to directly access Mailgun's REST API:

// both lines are equivalent
mailgun.invoke("GET", `/log`, ["limit":"25"])

The return type for invoke will either be a Str:Obj or it will be a [Str:Obj][] list. Refer to the Mailgun documentation on expected result.