verifyEmail.js 901 B

1234567891011121314151617181920212223242526272829
  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. from: config.get("mail.from"),
  15. to,
  16. subject: "Please verify your email",
  17. html: `
  18. Hello there ${username},
  19. <br>
  20. <br>
  21. To verify your email, please visit <a href="${url}/auth/verify_email?code=${code}">${url}/auth/verify_email?code=${code}</a>.
  22. `
  23. };
  24. mail.runJob("SEND_MAIL", { data })
  25. .then(() => cb())
  26. .catch(err => cb(err));
  27. };