System Information
- Strapi Version:
- Operating System:
- Database:
- Node Version:
- NPM Version:
- Yarn Version:
I cannot send emails using the strapi email plugin. My code in plugins.js is
// EMAIL Plugin
module.exports = ({ env }) => ({
// ...
email: {
config: {
provider: 'nodemailer',
providerOptions: {
host: env('SMTP_HOST'),
port: env('SMTP_PORT',587),
tls : { rejectUnauthorized: true },
secure: true, // use SSL
auth: {
user: env('SMTP_USERNAME'),
pass: env('SMTP_PASSWORD'),
},
// ... any custom nodemailer options
},
settings: {
defaultFrom: env('SMTP_USERNAME_FROM'),
defaultReplyTo: env('SMTP_USERNAME_REPLY'),
},
},
},
// ...
});
My envorornment variables
SMTP_PROVIDER=nodemailer
SMTP_HOST=smtp.gmail.com
SMTP_PORT=465
SMTP_USERNAME=my email
GMAIL uses app password
SMTP_PASSWORD=password
SMTP_USERNAME_FROM=myemail
SMTP_USERNAME_REPLY=myemail
and the controller is
// File /api/email/controllers/registration.js
‘use strict’
/**
- Read the documentation () to implement custom controller functions
*/
module.exports = {
/**
- Sends an email to the recipient in the body of the request
*/
async send(ctx){
const body = ctx.request.body
const sendTo = body.email
strapi.log.debug(`Trying to send an email to ${sendTo}`)
try {
const emailOptions = {
to: sendTo,
subject: 'This is a test',
html: `<h1>Welcome to bananatool!</h1><p>You can start posting and booking now.</p>`,
}
await strapi.plugins['email'].services.email.send(emailOptions)
strapi.log.debug(`Email sent to ${sendTo}`)
ctx.send({ message: 'Email sent' })
} catch (err) {
strapi.log.error(`Error sending email to ${sendTo}`, err)
console.log(err)
ctx.send({ error: 'Error sending email' })
}
},
}
I send a post request with postman to /api/registrationemail and it does not send any email, it freezes in “Sending request”