Skip to content

Commit

Permalink
Merge pull request #55 from BigWhaleLabs/add-mailgun
Browse files Browse the repository at this point in the history
add mailgun
  • Loading branch information
upacyxou authored Sep 25, 2023
2 parents f1052fc + dd20c71 commit 0b2ac3b
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ ETH_RPC_POLYGON=https://example.com/rpc
KETL_HASHES_SOURCE=https://eth.example.com
DOMAIN=verify.sealcred.xyz
ENVIRONMENT=development
MAILGUN_API_KEY=00000000000000000000000000000000
MAILGUN_DOMAIN=example.com
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ And you should be good to go! Feel free to fork and submit pull requests.
| `DOMAIN` | Domain name for caddy, DNS should point at the IP where the code is hosted |
| `ENVIRONMENT` | Environment name (defaults to `development`) |
| `KETL_HASHES_SOURCE` | Link to merkle tree hashes for Ketl |
| `MAILGUN_API_KEY` | Mailgun API key |
| `MAILGUN_DOMAIN` | Mailgun Domain |

Also, please, consider looking at `.env.sample`.

Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
},
"dependencies": {
"@big-whale-labs/constants": "^0.2.15",
"@big-whale-labs/ketl-email": "^0.1.15",
"@big-whale-labs/ketl-email": "^0.2.1",
"@big-whale-labs/seal-cred-email": "^1.1.2",
"@hapi/boom": "^10.0.0",
"@koa/cors": "^4.0.0",
"@types/node-persist": "^3.1.4",
"@types/nodemailer-mailgun-transport": "^1.4.4",
"@zk-kit/incremental-merkle-tree": "^1.0.0",
"amala": "^8.0.2",
"axios": "^1.5.0",
Expand All @@ -36,7 +37,8 @@
"koa-bodyparser": "^4.3.0",
"koa-router": "^12.0.0",
"node-persist": "^3.1.3",
"nodemailer": "^6.8.0",
"nodemailer": "^6.9.5",
"nodemailer-mailgun-transport": "^2.1.5",
"uuid": "^9.0.0"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/verify-ketl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export default class VerifyKetlController {
domain,
forKetl: true,
secret: secret.join(''),
subject: "Here's your token!",
subject: "Here's your signup code!",
to: email,
})
}
Expand All @@ -108,7 +108,7 @@ export default class VerifyKetlController {
domain,
forKetl: true,
secret: `${type}${attestationHash}${signature}`,
subject: "Here's your token!",
subject: "Here's signup code!",
to: email,
})
}
Expand Down
2 changes: 2 additions & 0 deletions src/helpers/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export default cleanEnv(process.env, {
default:
'https://raw.githubusercontent.com/BigWhaleLabs/ketl-attestation-token/main',
}),
MAILGUN_API_KEY: str(),
MAILGUN_DOMAIN: str(),
PORT: num({ default: 1337 }),
SMTP_PASS: str(),
SMTP_USER: str(),
Expand Down
23 changes: 20 additions & 3 deletions src/helpers/sendEmail.ts
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'
Expand All @@ -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,
Expand All @@ -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)
Expand Down
94 changes: 83 additions & 11 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ __metadata:
languageName: node
linkType: hard

"@big-whale-labs/ketl-email@npm:^0.1.15":
version: 0.1.15
resolution: "@big-whale-labs/ketl-email@npm:0.1.15"
"@big-whale-labs/ketl-email@npm:^0.2.1":
version: 0.2.1
resolution: "@big-whale-labs/ketl-email@npm:0.2.1"
dependencies:
envalid: ^7.3.1
mjml: ^4.13.0
Expand All @@ -51,7 +51,7 @@ __metadata:
react: ^18.2.0
react-dom: ^18.2.0
source-map-support: ^0.5.21
checksum: 38e63692e918c7cc8eb33218dcf18cddf97f9a98918c8fc29b2efe83274003528e766b709b49dcf03c7b0fe562b8dcd9237928f35a33b87a41f5da4c97769e5c
checksum: 190a64fd3fd14ec2d0acc7fa3fa2cdc063e21ad237a52eb184dfc4b3106e41faca8d63e8722e4ec93f11b0f79a0683c47649c8fe1fc523a6280d195f98944799
languageName: node
linkType: hard

Expand Down Expand Up @@ -1304,6 +1304,24 @@ __metadata:
languageName: node
linkType: hard

"@types/nodemailer-mailgun-transport@npm:^1.4.4":
version: 1.4.4
resolution: "@types/nodemailer-mailgun-transport@npm:1.4.4"
dependencies:
"@types/nodemailer": "*"
checksum: 1283b7226c1c5d251a1626745eef67f44e4728c4955a31f457644aaac9a6114773a8dce7deef2175e74d115265d162e56a4f57521457cf5097be37b7bcf3a165
languageName: node
linkType: hard

"@types/nodemailer@npm:*":
version: 6.4.11
resolution: "@types/nodemailer@npm:6.4.11"
dependencies:
"@types/node": "*"
checksum: 1069c30ad416add6035ee1437c93dccb846fc389bd6b31c36d094d90f4626f0db63f7ba88fddc3c4d448570dcbef59051e19b868f5f1038a472ef0e8dc169637
languageName: node
linkType: hard

"@types/nodemailer@npm:^6.4.6":
version: 6.4.6
resolution: "@types/nodemailer@npm:6.4.6"
Expand Down Expand Up @@ -1722,7 +1740,7 @@ __metadata:
dependencies:
"@big-whale-labs/bwl-eslint-backend": ^1.0.3
"@big-whale-labs/constants": ^0.2.15
"@big-whale-labs/ketl-email": ^0.1.15
"@big-whale-labs/ketl-email": ^0.2.1
"@big-whale-labs/prettier-config": ^1.1.3
"@big-whale-labs/seal-cred-email": ^1.1.2
"@hapi/boom": ^10.0.0
Expand All @@ -1736,6 +1754,7 @@ __metadata:
"@types/node": ^18.11.9
"@types/node-persist": ^3.1.4
"@types/nodemailer": ^6.4.6
"@types/nodemailer-mailgun-transport": ^1.4.4
"@types/uuid": ^8.3.4
"@zk-kit/incremental-merkle-tree": ^1.0.0
amala: ^8.0.2
Expand All @@ -1751,7 +1770,8 @@ __metadata:
koa-router: ^12.0.0
module-alias: ^2.2.2
node-persist: ^3.1.3
nodemailer: ^6.8.0
nodemailer: ^6.9.5
nodemailer-mailgun-transport: ^2.1.5
prettier: ^2.8.0
source-map-support: ^0.5.21
tsc-watch: ^5.0.3
Expand Down Expand Up @@ -1780,7 +1800,7 @@ __metadata:
languageName: node
linkType: hard

"axios@npm:^1.5.0":
"axios@npm:^1.3.3, axios@npm:^1.5.0":
version: 1.5.0
resolution: "axios@npm:1.5.0"
dependencies:
Expand Down Expand Up @@ -1815,6 +1835,13 @@ __metadata:
languageName: node
linkType: hard

"base-64@npm:^1.0.0":
version: 1.0.0
resolution: "base-64@npm:1.0.0"
checksum: d10b64a1fc9b2c5a5f39f1ce1e6c9d1c5b249222bbfa3a0604c592d90623caf74419983feadd8a170f27dc0c3389704f72faafa3e645aeb56bfc030c93ff074a
languageName: node
linkType: hard

"base64-js@npm:^1.3.1":
version: 1.5.1
resolution: "base64-js@npm:1.5.1"
Expand Down Expand Up @@ -1882,6 +1909,13 @@ __metadata:
languageName: node
linkType: hard

"bluebird@npm:^3.1.1":
version: 3.7.2
resolution: "bluebird@npm:3.7.2"
checksum: 869417503c722e7dc54ca46715f70e15f4d9c602a423a02c825570862d12935be59ed9c7ba34a9b31f186c017c23cac6b54e35446f8353059c101da73eac22ef
languageName: node
linkType: hard

"bn.js@npm:^4.11.9":
version: 4.12.0
resolution: "bn.js@npm:4.12.0"
Expand Down Expand Up @@ -2329,6 +2363,15 @@ __metadata:
languageName: node
linkType: hard

"consolidate@npm:^0.15.1":
version: 0.15.1
resolution: "consolidate@npm:0.15.1"
dependencies:
bluebird: ^3.1.1
checksum: 5a44ee975f8403dd3ff8ff3472fda7db0484b19f153eaac38e784465505a0741939c72d703befda7c75649739fc7a68f9659a86e2a62469336a8d531bd7a10df
languageName: node
linkType: hard

"content-disposition@npm:~0.5.2":
version: 0.5.4
resolution: "content-disposition@npm:0.5.4"
Expand Down Expand Up @@ -4544,6 +4587,17 @@ __metadata:
languageName: node
linkType: hard

"mailgun.js@npm:^8.0.1":
version: 8.2.2
resolution: "mailgun.js@npm:8.2.2"
dependencies:
axios: ^1.3.3
base-64: ^1.0.0
url-join: ^4.0.1
checksum: 9736fca6e845a3cfab471ec59764bb9365570cdee127f22e1e25e4ee4de2a4d618c66b4bee372949f469d0d6b86cffe49974a9626bfcb0f5cf36ac1fa6016799
languageName: node
linkType: hard

"make-fetch-happen@npm:^10.0.3":
version: 10.1.8
resolution: "make-fetch-happen@npm:10.1.8"
Expand Down Expand Up @@ -5300,10 +5354,21 @@ __metadata:
languageName: node
linkType: hard

"nodemailer@npm:^6.8.0":
version: 6.8.0
resolution: "nodemailer@npm:6.8.0"
checksum: e1827df714d207a00f1bf8012e767826862467b72440fc9c37cf238a14d01a4c591b7657f4d1805bfb2764883c07aa9f2e31ee96a5fec51ccf1e6ad6dd01bd1d
"nodemailer-mailgun-transport@npm:^2.1.5":
version: 2.1.5
resolution: "nodemailer-mailgun-transport@npm:2.1.5"
dependencies:
consolidate: ^0.15.1
form-data: ^4.0.0
mailgun.js: ^8.0.1
checksum: b003b00e428e9896f2e1e9892a3a78d3c2220e34c1e8766e2eeed9a8154a9edf41ac0eb95c2e7631a59314db81f90d2e7f72b2a5d82e3450c22caf050685e9c4
languageName: node
linkType: hard

"nodemailer@npm:^6.9.5":
version: 6.9.5
resolution: "nodemailer@npm:6.9.5"
checksum: e39282795e09f0685691b1511f74e2dc4703ba6ecd55d964c2f8a1b54591e5b284228c90cd6a203b498a5a1ea2610415306e8d7eda0b3cd9ebdcb210f05b2846
languageName: node
linkType: hard

Expand Down Expand Up @@ -6570,6 +6635,13 @@ __metadata:
languageName: node
linkType: hard

"url-join@npm:^4.0.1":
version: 4.0.1
resolution: "url-join@npm:4.0.1"
checksum: f74e868bf25dbc8be6a8d7237d4c36bb5b6c62c72e594d5ab1347fe91d6af7ccd9eb5d621e30152e4da45c2e9a26bec21390e911ab54a62d4d82e76028374ee5
languageName: node
linkType: hard

"util-deprecate@npm:^1.0.1":
version: 1.0.2
resolution: "util-deprecate@npm:1.0.2"
Expand Down

0 comments on commit 0b2ac3b

Please sign in to comment.