如何使用Dialoflow发送电子邮件进行Google操作

Yur*_*ves 1 actions-on-google dialogflow-es

我四处寻找可以找到一种解决方案,该方案可以运行发送电子邮件但无法找到任何解决方案的意图。有人可以帮忙吗?

Sai*_*ant 5

您可以在dialogflow Webhook实现意图中使用nodemailer发送电子邮件。

确保在此处启用安全性较低的应用程序以使用gmail发送电子邮件。

从您的意图使用nodemailer发送电子邮件的代码:

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

      const nodemailer = require('nodemailer');
      const transporter = nodemailer.createTransport({
        service: 'gmail',
        auth: {
          user: 'youremail@gmail.com',
          pass: 'yourPassword'
        }
      });

      var mailOptions = {
        from: 'youremail@gmail.com',
        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);
        }
      });

});
Run Code Online (Sandbox Code Playgroud)

如果您正在使用行内编辑遵循寻求帮助。

希望有帮助!