title: Implement a mailing solution in Express nodejs
body: <p>I'm creating an API that handles account verification via email, password recovery and possibly other things.</p>
  
  <p>I want to create one place to send emails across my entire API. 
  i'm using nodeMailer. </p>
  
  <p>My current setup is i'm a calling a method on the user model that send EmailVerification email.</p>
  
  <p>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: </p>
  
  <pre><code>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);
  };
  </code></pre>
  
  <p>and this is my sendMail function: </p>
  
  <pre><code>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 &lt;a href="www.example.com/email_verif/${user.emailVerificationToken}"&gt;link&lt;/a&gt; to verify your email`
      };
  
      transporter.sendMail(mailOptions, function(error, info){
          if (error) {
              console.log(error);
          } else {
              console.log('Email sent: ' + info.response);
          }
      });
  }
  </code></pre>
  
  <p>Thank you</p>