mailgun
Mailgun is an email automation service.
Usage
import { mailgun } from 'netzo/apis/mailgun.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 API client api
.
Param | Type | Default | Description |
---|---|---|---|
apiKey | string | Deno.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.
Find mailing lists
Find all mailing lists.
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.
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.
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.
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.
const resultData = await api.v3.lists[LIST_ADDRESS].members[MEMBER_ADDRESS].delete<DeleteMemberResult>()