Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

email service

default discord avatar
muperdev2 years ago
7

Hi, I need help to config email service in my payload cms



I already read the doc but still I think some part are a little bit confusing

  • default discord avatar
    pandazaar2 years ago
    const transport = nodemailer.createTransport({
        host: process.env.PAYLOAD_NODEMAILER_HOST,
        port: parseInt(process.env.PAYLOAD_NODEMAILER_PORT),
        secure: false,
        auth: {
          user: process.env.PAYLOAD_NODEMAILER_USER,
          pass: process.env.PAYLOAD_NODEMAILER_PASSWORD,
        },
      });
    // Initialize Payload
      await payload.init({
        secret: process.env.PAYLOAD_SECRET,
        mongoURL: process.env.MONGODB_URI,
        express: app,
        onInit: async () => {
          payload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`);
        },
    email: {
          fromAddress: 'example@example.com',
          fromName: 'example',
          transport,
        },
      });
    
    
    ./env
    # using mailtrap here
    PAYLOAD_NODEMAILER_HOST=sandbox.smtp.mailtrap.io
    PAYLOAD_NODEMAILER_PORT=465
    PAYLOAD_NODEMAILER_USER=userId
    PAYLOAD_NODEMAILER_PASSWORD=userPassword


    here's mine that's using mailtrap for dev

  • discord user avatar
    denolfe
    2 years ago
    I already read the doc but still I think some part are a little bit confusing

    You'll have to be more specific in what is confusing. What have you tried? Are you getting an error? Are you using an existing nodemailer transport?

  • default discord avatar
    muperdev2 years ago

    actually I'm not a backend developer so I'm not very professional in it, but let me try the sample panda shared to me



    hi, panda please can you explain me that how you'll use this config through your code, because I want to use it whenever the user submit a form

  • default discord avatar
    pandazaar2 years ago

    You use req.payload.sendEmail(...) and fill in the args, sorry I'm not at home now, if you struggle I can help you later

  • discord user avatar
    denolfe
    2 years ago

    So in order to use an email within Payload, you'll need to sign up for an email service somewhere. Some workplaces have an SMTP server that can be used. Others used like AWS SES, Sendgrid, and more. Have you decided which service you'll be using?

  • default discord avatar
    muperdev2 years ago

    I decided to use mailtrap which is good I think, isn't it?



    then I should chose SMTP in their configuration ?





    I configured the file, but my question is where is the message and body



    and how can I call this with req.payload.sendEmail



    because I need to use this whenever the user post data to backend



    all done guys, thank you

  • discord user avatar
    denolfe
    2 years ago

    Yeah, once configured, it will be automatically used by

    sendEmail

    Glad you got it sorted

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.