Password Reset Email not sending

default discord avatar
Daniel502last year
11

i got locked out of the admin dashboard (totally my fault), and i can't remember my password. i'm running the project manually and when i fire up the server, i get this error : ' (payload): There was a problem setting up the mock email handler'. it's my first time working with payload . with any headless CMS for that matter. i'd really appreciate any help i can get. thanks in advance



this is my repo if it'll help :

https://github.com/neo1415/nextjs-custom-server
  • default discord avatar
    nballlast year

    I've had a similar issue with the same code. Planning to revisit today. Not sure I can help but at least provide more data points.



    I think I removed the admin user from the DB directly then tried to reinitialize a new user to get back in. Obviously that's not a good solution.

  • default discord avatar
    Daniel502last year

    Oh, thank you, how did you go about that then ?



    "use strict";


    var

    importDefault = (this && this.

    importDefault)

    function (mod) {
    return (mod && mod.esModule) ? mod : { "default": mod };
    };
    Object.defineProperty(exports, "
    esModule", { value: true });
    const nodemailer_1 = __importDefault(require("nodemailer"));
    const mockEmailHandler = async (emailConfig) => {
    const testAccount = await nodemailer_1.default.createTestAccount();
    const smtpOptions = {
    ...emailConfig,
    host: 'smtp.ethereal.email',
    port: 587,
    secure: false,
    fromName: emailConfig.fromName

    'Payload CMS',


    fromAddress: emailConfig.fromAddress || 'info@payloadcms.com',


    auth: {


    user: testAccount.user,


    pass: testAccount.pass,


    },


    };


    return {


    account: testAccount,


    transport: nodemailer_1.default.createTransport(smtpOptions),


    };


    };


    exports.default = mockEmailHandler;


    //# sourceMappingURL=mockHandler.js.map



    this is how my mockHandler looks like

  • discord user avatar
    jesschow
    last year

    Hey @Daniel502 I've got myself locked out many many times.



    If you are okay with losing your existing users, you can do what @nball said and delete your user collection from the database. To do this, you need to open up MongoDB, connect and find your

    nem-health

    database, right click on the Users collection and hit

    drop

    . Then navigate to

    localhost:3000/admin

    and you should be prompted to create a new first user.



    Or we can go the mock email route and use the ethereal capture service. Add this to your payload.init (the fromName/address can be any value):



    payload.init({
      email: {
        fromName: 'Admin',
        fromAddress: 'admin@example.com',
        logMockCredentials: true,
      },
      // ...
    });


    Restart your server - this time you will see mock credentials in your terminal, you will need these later.



    Navigate back to the admin login in your browser, click

    Forgot Password

    and follow the instructions.



    Now head to the mock email provider:

    https://ethereal.email

    and use the credentials that were output to your terminal when you started the server. You should see the

    Reset Password

    email and be able to follow the link to reset your password.

  • default discord avatar
    Daniel502last year

    thank you so much for replying , i really appreciate it. the thing is i don't have a payload.init in my code .



    "use strict";


    var

    importDefault = (this && this.

    importDefault)

    function (mod) {
    return (mod && mod.esModule) ? mod : { "default": mod };
    };
    Object.defineProperty(exports, "
    esModule", { value: true });
    const nodemailer_1 = __importDefault(require("nodemailer"));
    const mockEmailHandler = async (emailConfig) => {
    const testAccount = await nodemailer_1.default.createTestAccount();
    const smtpOptions = {
    ...emailConfig,
    host: 'smtp.ethereal.email',
    port: 587,
    secure: false,
    fromName: emailConfig.fromName

    'Payload CMS',


    fromAddress: emailConfig.fromAddress || 'info@payloadcms.com',


    auth: {


    user: testAccount.user,


    pass: testAccount.pass,


    },


    };


    return {


    account: testAccount,


    transport: nodemailer_1.default.createTransport(smtpOptions),


    };


    };


    exports.default = mockEmailHandler;


    //# sourceMappingURL=mockHandler.js.map



    this is the current code.

  • discord user avatar
    jesschow
    last year

    In the repo you shared it looks like you have payload.init() here?

    https://github.com/neo1415/nextjs-custom-server/blob/master/server.ts
  • default discord avatar
    Daniel502last year

    Thanks so much , I'm in again. It worked . Blessings

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.