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
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
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?
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
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
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?
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
Yeah, once configured, it will be automatically used by
sendEmail
Glad you got it sorted
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.