Skip to content

Commit

Permalink
Possibility to customize mailgun api base url (#78)
Browse files Browse the repository at this point in the history
* - fix: mailgun apiBasePath configuration added

* - fix: typescript syntax removed

* - clean: host naming
- api version configuration added

* - flow + tests
  • Loading branch information
Badji Lounes authored Jun 29, 2021
1 parent 1a5e2cb commit d0799df
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/providers/email/mailgun.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ export default class EmailMailgunProvider {
id: string = 'email-mailgun-provider'
apiKeyBase64: string
domainName: string
host: string
version: string

constructor (config: Object) {
this.apiKeyBase64 = Buffer.from(`api:${config.apiKey}`).toString('base64')
this.domainName = config.domainName
this.host = config.host || 'api.mailgun.net'
this.version = config.version || 'v3'
}

async send (request: EmailRequestType): Promise<string> {
Expand All @@ -35,7 +39,7 @@ export default class EmailMailgunProvider {
if (id) form.append('v:Notification-Id', id)
if (userId) form.append('v:User-Id', userId)

const response = await fetch(`https://api.mailgun.net/v3/${this.domainName}/messages`, {
const response = await fetch(`https://${this.host}/${this.version}/${this.domainName}/messages`, {
method: 'POST',
headers: {
Authorization: `Basic ${this.apiKeyBase64}`,
Expand Down

0 comments on commit d0799df

Please sign in to comment.