System Information
- Strapi Version: 4.0.4
- Operating System: Ubuntu
- Database: SQLite
- Node Version: 16.3
- NPM Version: 8.3
Hello!
I’m trying to add an email notification on new item of collection type “feedback” was created.
I’ve done all steps from article below, but it still doesn’t work.
- Created collection type feedback with all needed fields
- Created src/api/email/services/email.js with code (domain and pass changed)
- Installed nodemailer via npm
- Changed src/feedback/controllers/feedback.js:
But then I have created new feedback via Strapi Admin nothing was happed.
The same result for creating feedback via form on frontend.
In DB all feedback’s items are store properly.
But there is no email notification or even console.log output.
"use strict";
/**
* src/api/email/services/email.js
*/
const { createCoreService } = require("@strapi/strapi").factories;
const nodemailer = require("nodemailer"); // Requires nodemailer to be installed (npm install nodemailer)
// Create reusable transporter object using SMTP transport.
const transporter = nodemailer.createTransport({
host: "smtp.yandex.ru",
port: 465,
secure: true,
auth: {
user: "noreply@mydomain.com",
pass: "mypassword",
},
});
module.exports = createCoreService("api::feedback.feedback", ({ strapi }) => ({
send(from, to, subject, text) {
// Setup e-mail data.
const options = {
from,
to,
subject,
text,
};
// Return a promise of the function that sends the email.
return transporter.sendMail(options);
},
}));
"use strict";
/**
* src/feedback/controllers/feedback.js
*/
const { createCoreController } = require("@strapi/strapi").factories;
module.exports = createCoreController(
"api::feedback.feedback",
({ strapi }) => ({
async signup(ctx) {
const { userData } = ctx.body;
console.log(userData); // just for test
strapi
.service("api::email.email")
.send("noreply@mydomain.com", "info@mydomain.com", "Welcome", "...");
// Send response to the server.
ctx.send({
ok: true,
});
},
})
);