diff --git a/backend/mailgun/mailgun.js b/backend/mailgun/mailgun.js new file mode 100644 index 0000000..594b5d4 --- /dev/null +++ b/backend/mailgun/mailgun.js @@ -0,0 +1,30 @@ +const mailgun = require("mailgun-js"); +const DOMAIN = "sandboxb488ae9cba904e73936d81f35b2ee781.mailgun.org"; +const mg = mailgun({ + apiKey: "d05c4d067d69c940d3dac93769dd87a2-fe066263-f6136332", + domain: DOMAIN +}); + +const sendInvite = async (newUser, email, familyName, inviteLink) => { + const data = { + from: "Mailgun Sandbox ", + to: email, + subject: "Welcome to BTC Family!", + text: + `Hi ${newUser}, + You are invited to join the ${familyName} family wallet! + + Click here: ${inviteLink} to accept your invitation! + ` + }; + + await mg.messages().send(data, function (error, body) { + if (error) { + console.error("Invite failed:", error) + } else { + console.log("Invite success:", body); + } + }); +} + +export { sendInvite } \ No newline at end of file diff --git a/backend/package.json b/backend/package.json index 8b59e4b..2022927 100644 --- a/backend/package.json +++ b/backend/package.json @@ -18,6 +18,7 @@ "express": "^4.17.3", "firebase-admin": "^10.0.2", "http-errors": "^2.0.0", + "mailgun-js": "^0.22.0", "morgan": "^1.10.0", "nodemon": "^2.0.15", "opennode": "^1.3.0",