Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I send an email with Dialoflow for Google actions

I have looked all over to find a solution to run an intent that sends an email but cannot find any solutions. Can anyone help?

like image 358
Yuri Alves Avatar asked Dec 24 '22 02:12

Yuri Alves


1 Answers

You can use nodemailer in your dialogflow webhook fulfillment intent to send emails.

Make sure to enable less secure apps here to use gmail to send emails.

Code for sending emails using nodemailer from your intent :

app.intent('sendMail', (conv, params) => {

      const nodemailer = require('nodemailer');
      const transporter = nodemailer.createTransport({
        service: 'gmail',
        auth: {
          user: '[email protected]',
          pass: 'yourPassword'
        }
      });

      var mailOptions = {
        from: '[email protected]',
        to: email, //receiver email 
        subject: 'Mail subject',
        text: 'mail body'
      };

      transporter.sendMail(mailOptions, function (error, info) {
        if (error) {
          console.log(error);
        } else {
          console.log('Email sent: ' + info.response);
        }
      });

});

If you are using inline editor follow this for assistance.

Hope that helps!

like image 136
Sairaj Sawant Avatar answered May 14 '23 05:05

Sairaj Sawant