Implement a mailing solution in Express nodejs

Implement a mailing solution in Express nodejs



I'm creating an API that handles account verification via email, password recovery and possibly other things.



I want to create one place to send emails across my entire API.
i'm using nodeMailer.



My current setup is i'm a calling a method on the user model that send EmailVerification email.



I want to create a template outside the User model that could send either password recovery, email verification or other things.. Depending on the params that i pass to the function.
My user model:


userSchema.methods.generateEmailVerificationToken = function()
const token = jwt.sign(_id: this._id, role: this.role,
config.get('jwtPrivateKey'));
return token;
;

userSchema.methods.generateAuthToken = function()
const token = jwt.sign(_id: this._id, role: this.role,
config.get('jwtPrivateKey'));
return token;
;

userSchema.methods.sendEmailVerification = function (user)
sendMail(user);
;



and this is my sendMail function:


const nodemailer = require('nodemailer');

module.exports = function sendMail (user)

const transporter = nodemailer.createTransport(
service: 'gmail',
auth:
user: 'mymail@gmail.com',
pass: 'mypass'

);

const mailOptions =
from: 'mymail@gmail.com',
to: user.email,
subject: 'Email verification.',
html: `Please click this <a href="www.example.com/email_verif/$user.emailVerificationToken">link</a> to verify your email`
;

transporter.sendMail(mailOptions, function(error, info)
if (error)
console.log(error);
else
console.log('Email sent: ' + info.response);

);



Thank you





You'll need to show us what you have so far and what errors or issues you are seeing. We can't help otherwise!
– jakerella
Aug 27 at 14:14









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế