Send mail after save for each user-email in collection

default discord avatar
zochh12 months ago
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
    12 months ago

    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
    zochh12 months ago

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

    STMP

    , wrote

    SMTP

    insread

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.