generated from Borodutch/backend-starter
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from BigWhaleLabs/add-mailgun
add mailgun
- Loading branch information
Showing
7 changed files
with
115 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import * as mg from 'nodemailer-mailgun-transport' | ||
import { createTransport } from 'nodemailer' | ||
import { generateTokenHtml as scEmail } from '@big-whale-labs/seal-cred-email' | ||
import env from '@/helpers/env' | ||
|
@@ -16,6 +17,15 @@ const emailer = createTransport({ | |
secure: true, | ||
}) | ||
|
||
const emailerMailgun = createTransport( | ||
mg({ | ||
auth: { | ||
api_key: env.MAILGUN_API_KEY, | ||
domain: env.MAILGUN_DOMAIN, | ||
}, | ||
}) | ||
) | ||
|
||
export default async function ({ | ||
domain, | ||
forKetl, | ||
|
@@ -35,13 +45,20 @@ export default async function ({ | |
: scEmail({ domain, secret }) | ||
|
||
const from = forKetl ? 'Ketl' : 'SealCred' | ||
const fromEmail = forKetl | ||
? '[email protected]' | ||
: '[email protected]' | ||
console.log(`Sending email to ${to}`) | ||
await emailer.sendMail({ | ||
from: `"${from}" <${user}>`, | ||
|
||
const info = { | ||
from: `"${from}" <${fromEmail}>`, | ||
html, | ||
subject, | ||
to, | ||
}) | ||
} | ||
|
||
forKetl ? await emailerMailgun.sendMail(info) : await emailer.sendMail(info) | ||
|
||
console.log(`Email sent to ${to}`) | ||
} catch (error) { | ||
console.error(error instanceof Error ? error.message : error) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters