#1- Add library NodeMailer: "nodemailer": "6.4.6" at **package.json
#2- Create your Cloud Function in the Fulfillment: -Add in your index.js the const nodemailer
const nodemailer = require("nodemailer");
-Now, map your intent with a Handler: intentMap.set('Notify2Email', NotifyHandler);
-Handle the parameters to the Transporter: Capture dynamic values from the conversation such as email, name, etc: SMTP is the protocol that we are going to use to connect our Gmail hosting
function NotifyHandler (agent) { const {email, name} = agent.parameters; const transporter = nodemailer.createTransport({ host: 'smtp.mail.com ', port: 465, service: 'gmail', auth: { user: '[email protected]', pass: 'YourSecurePasswordHere' } }); const mailOptions = { from: "YourMailUserID", // Here insert the sender mail address to: email, // Users email receivers subject: "Bot Notification", // Here insert your Subject line html: '
Hello ${name}
' // Here insert the body of the Email };El transporter es el que nos va a permitir: transporter is going to be an object that is able to send mail transport is the transport configuration object, connection url or a transport plugin instance defaults is an object that defines default values for mail options
transporter.sendMail(mailOptions, function (err, info) { if(err) console.log(err); else console.log(info); });
}