Skip to content
On this page
netzo/apis/mailgun

Mailgun

Mailgun is an email automation service that allows you to send, receive, and track email. It is a powerful tool for building email automation into your app.

  • labels: email, email-marketing, email-automation, email-tracking
  • authentication: apiKey

Usage

ts
import { mailgun } from 'https://deno.land/x/netzo/apis/mailgun/mod.ts'

const { api } = mailgun({
  apiKey: Deno.env.get('MAILGUN_API_KEY')
})
import { mailgun } from 'https://deno.land/x/netzo/apis/mailgun/mod.ts'

const { api } = mailgun({
  apiKey: Deno.env.get('MAILGUN_API_KEY')
})

Configuration

The mailgun factory function expects an object with the following, and returns an object with an HTTP client api.

ParamTypeDefaultDescription
apiKeystringDeno.env.get('MAILGUN_API_KEY')the api key to use for authentication

Refer to the API documentation to get the required information.

Examples

The following examples assume you have created an api client instance. Refer to the type definitions for all exported types to pass to the api client for typed responses.

Find mailing lists

Find all mailing lists.

ts
import type { MailingLists, QueryMailingLists } from 'netzo/apis/mailgun/types.ts'

const query: QueryMailingLists = {}
const result = await api.v3.lists.pages.get<MailingLists>(query)
const resultData = result.items
import type { MailingLists, QueryMailingLists } from 'netzo/apis/mailgun/types.ts'

const query: QueryMailingLists = {}
const result = await api.v3.lists.pages.get<MailingLists>(query)
const resultData = result.items

Add mailing list

Add a new mailing list.

ts
import type { AddOrUpdateListResult, DataAddMailingList } from 'netzo/apis/mailgun/types.ts'

const data: DataAddMailingList = {
  address: '[email protected]',
  name: 'Newsletter'
}
const result = await api.v3.lists.post<AddOrUpdateListResult>(data)
const resultData = result.list
import type { AddOrUpdateListResult, DataAddMailingList } from 'netzo/apis/mailgun/types.ts'

const data: DataAddMailingList = {
  address: '[email protected]',
  name: 'Newsletter'
}
const result = await api.v3.lists.post<AddOrUpdateListResult>(data)
const resultData = result.list

Update mailing list

Update a mailing list by its email address.

ts
import type { AddOrUpdateListResult, DataUpdateMailingList } from 'netzo/apis/mailgun/types.ts'

const data: DataUpdateMailingList = {
  name: 'Updated name'
}
const result = await api.v3.lists[LIST_ADDRESS].put<AddOrUpdateListResult>(data)
const resultData = result.list
import type { AddOrUpdateListResult, DataUpdateMailingList } from 'netzo/apis/mailgun/types.ts'

const data: DataUpdateMailingList = {
  name: 'Updated name'
}
const result = await api.v3.lists[LIST_ADDRESS].put<AddOrUpdateListResult>(data)
const resultData = result.list

Add member to mailing list

Add a new email address to a mailing list.

ts
import type { AddMemberResult, DataAddMember } from 'netzo/apis/mailgun/types.ts'

const data: DataAddMember = {
  address: '[email protected]'
}
const result = await api.v3.lists[LIST_ADDRESS].members.post<AddMemberResult>(data)
const resultData = result.member
import type { AddMemberResult, DataAddMember } from 'netzo/apis/mailgun/types.ts'

const data: DataAddMember = {
  address: '[email protected]'
}
const result = await api.v3.lists[LIST_ADDRESS].members.post<AddMemberResult>(data)
const resultData = result.member

Delete mailing list member

Remove an email from a mailing list.

ts
import type { DeleteMemberResult } from 'netzo/apis/mailgun/types.ts'

const resultData = await api.v3.lists[LIST_ADDRESS].members[MEMBER_ADDRESS].delete<DeleteMemberResult>()
import type { DeleteMemberResult } from 'netzo/apis/mailgun/types.ts'

const resultData = await api.v3.lists[LIST_ADDRESS].members[MEMBER_ADDRESS].delete<DeleteMemberResult>()

References