Created
September 30, 2022 20:46
-
-
Save iMichaelOwolabi/4da4997767773f314914dbdefbd5c4db to your computer and use it in GitHub Desktop.
Email transporter code for passwordless auth app
This file contains hidden or 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
import nodemailer from 'nodemailer'; | |
import { config } from 'dotenv'; | |
config() | |
export const emailSender = async (to, firstName, token) => { | |
const trasporter = await nodemailer.createTransport({ | |
host: process.env.MAILGUN_SMTP_HOSTNAME, | |
port: process.env.SMTP_PORT, | |
secure: false, | |
auth: { | |
user: process.env.MAILGUN_SMTP_USERNAME, | |
pass: process.env.MAILGUN_SMTP_PASSWORD, | |
}, | |
}); | |
await trasporter.sendMail({ | |
from: `"Passwordless Auth" <[email protected]>`, // sender address | |
to: `${to}`, | |
subject: "Welcome to Passwordless Authentication", | |
html: `<p><b>Hey ${firstName},</b></p> <p>You are welcome to the world of passwordless authentication. Kindly click the link below to login: </p> | |
<a href='http://localhost:${process.env.PORT}/api/v1/auth/verify/${token}'>http://localhost:${process.env.PORT}/authenticate/${token}</a>. | |
`, | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment