Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const nodemailer = require("nodemailer");
- const smtpTransport = nodemailer.createTransport({
- service: "Gmail",
- auth: {
- user: "...@gmail.com",
- pass: "..."
- }
- });
- router.post('/...', (req, res) => {
- ...
- rand = Math.floor((Math.random() * 100) + 54);
- host = req.get('host');
- link = "http://" + host + "/api/users/verify?id=" + rand;
- let mailOptions = {
- from: smtpTransport.user,
- to: req.body.user_email,
- subject: "Please confirm your Email account",
- html: "Hello,<br> Please Click on the link to verify your email.<br><a href=" + link + ">Click here to verify</a>"
- }
- smtpTransport.sendMail(mailOptions, (err, res) => {
- if (!err) {
- res.status(200).json({
- message: 'Email sent successfully',
- });
- } else {
- return res.status(500).json({
- error: err
- });
- }
- });
- ...
- });
- router.get('/...', (req, res) => {
- if ((req.protocol + "://" + req.get('host')) == ("http://" + host)) {
- console.log("Domain is matched. Information is from Authentic email");
- if (req.query.id == rand) {
- console.log("email is verified");
- res.end("<h1>Email " + mailOptions.to + " is been Successfully verified");
- } else {
- console.log("email is not verified");
- res.end("<h1>Bad Request</h1>");
- }
- } else {
- res.end("<h1>Request is from unknown source");
- }
- });
Add Comment
Please, Sign In to add comment