Send mail after save for each user-email in collection

default discord avatar
zochh
last month
2

Hello, this is my code right now, I've got all the emails, but I'm confused with setting up the nodemailer part. I have my own STMP server with SSL, port: 465. How would I go setting it up?


const Posts: CollectionConfig = {
  // fields, admin and such
  hooks: {
    afterChange: [
      async (args) => {
        const emails = await payload
          .find({
            collection: "newsletter-emails",
            where: {
              and: [
                {
                  unsub: {
                    equals: false,
                  },
                },
              ],
            },
            limit: 9999,
          })
          .then((res) => res.docs);
      },
    ],
  },
};

export default Posts;
  • discord user avatar
    denolfe
    Payload Team
    last month

    You would configure a nodemailer SMTP transport as documented here:

    https://nodemailer.com/smtp/


    Then you'd pass that email transport in your config

    email

    property or in

    init

    . Both are supported.

  • default discord avatar
    zochh
    last month

    Yep, thanks- I've done that but the reason for not working was I misspelled

    STMP

    , wrote

    SMTP

    insread

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.