How to add custom email sending functionalities for verify email and forgot password ?

default discord avatar
Veera26
2 weeks ago
7

Hello, Do you have any idea about how to add our own custom email sending functionalities for verify email and forgot password auth operations ?



Right now, we are doing the email configuraton in payload.init .



We don't want do it. So, We have to write our own email sending functionalities and configure with verify email and forgot password functionalities.



Do you have the solution , feel free to share . Thanks

  • default discord avatar
    thisisnotchris
    2 weeks ago

    Good morning @Veera26



    On Auth-enbabled collections, you can override the generated email with something custom



    https://payloadcms.com/docs/authentication/config#forgot-password


    import { CollectionConfig } from 'payload/types';
    
    export const Customers: CollectionConfig = {
      slug: 'customers',
      auth: {
        forgotPassword: {
          generateEmailHTML: ({ req, token, user }) => {
            // Use the token provided to allow your user to reset their password
            const resetPasswordURL = `https://yourfrontend.com/reset-password?token=${token}`;
    
            return `
              <!doctype html>
              <html>
                <body>
                  <h1>Here is my custom email template!</h1>
                  <p>Hello, ${user.email}!</p>
                  <p>Click below to reset your password.</p>
                  <p>
                    <a href="${resetPasswordURL}">${resetPasswordURL}</a>
                  </p>
                </body>
              </html>
            `;
          }
        }
      }
    };
  • default discord avatar
    Veera26
    2 weeks ago

    Okay



    is there a way to disable the mockTransport email configuration ?

  • default discord avatar
    thisisnotchris
    2 weeks ago

    Hmm, I think you can disable it by setting logMockCredentials to false -

    https://payloadcms.com/docs/email/overview#mock-transport
Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

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