Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I can't send email to sendGrid #72

Open
rades12340 opened this issue Apr 1, 2019 · 0 comments
Open

I can't send email to sendGrid #72

rades12340 opened this issue Apr 1, 2019 · 0 comments

Comments

@rades12340
Copy link

rades12340 commented Apr 1, 2019

When I want to send an email to user when, is sends an email firstly created?

const crypto = require("crypto");
const User = require("../models/user");
const nodemailer = require("nodemailer");
const sendgridTransport = require("nodemailer-sendgrid-transport");
const bcrypt = require("bcryptjs");

const transporter = nodemailer.createTransport(
  sendgridTransport({
    auth: {
      api_key:
        "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"
    }
  })
);

exports.postReset = (req, res, next) => {
  crypto.randomBytes(32, (err, buffer) => {
    if (err) {
      console.log(err);
      return res.redirect("/reset");
    }
    const token = buffer.toString("hex");
    User.findOne({ email: req.body.email })
      .then(user => {
        if (!user) {
          req.flash("error", "No account with that email found.");
          return res.redirect("/reset");
        }
        user.resetToken = token;
        user.resetTokenExpiration = Date.now() + 10200000;
        return user.save();
      })
      .then(result => {
        res.redirect("/");
        transporter.sendMail(
          {
            to: req.body.email,
            from: "[email protected]",
            subject: "Password reset",
            html: `
            <p>You requested a password reset</p>
            <p>Click this <a href="http://localhost:3000/reset/${token}">link</a> to set a new password</p>
          `
          },
          (err, info) => {
            console.log(info.envelope);
            console.log(info.messageId);
          }
        );
      })
      .catch(err => console.log(err));
  });
};

But I got this message when resetting an email sent:

You requested a password reset

Click this link to set a new password

dfsdfasdfadfads

What is the reason for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant