verifyEmail.js 865 B

123456789101112131415161718192021222324252627
  1. import config from "config";
  2. import mail from "../index";
  3. /**
  4. * Sends a verify email email
  5. * @param {string} to - the email address of the recipient
  6. * @param {string} username - the username of the recipient
  7. * @param {string} code - the email reset code of the recipient
  8. * @param {Function} cb - gets called when an error occurred or when the operation was successful
  9. */
  10. export default (to, username, code, cb) => {
  11. const url = `${config.get("url.secure") ? "https" : "http"}://${config.get("url.host")}/backend`;
  12. const data = {
  13. to,
  14. subject: "Please verify your email",
  15. html: `
  16. Hello there ${username},
  17. <br>
  18. <br>
  19. To verify your email, please visit <a href="${url}/auth/verify_email?code=${code}">${url}/auth/verify_email?code=${code}</a>.
  20. `
  21. };
  22. mail.runJob("SEND_MAIL", { data })
  23. .then(() => cb())
  24. .catch(err => cb(err));
  25. };