verifyEmail.js 868 B

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