1

I'm working with dialog flow on Google home, and I have a program which sends an email (via Nodemailer), I would like to lock a function, and unlock it depending on the email's answer.

Maybe I could put a link inside the email as "if you agree with this, click on this link, otherwise don't".

Can I get the answer with my program? If yes, how?

Here is the function I use to send my email:

var transporter = nodemailer.createTransport({
  service: 'gmail',
  auth: {
    user: '**********',
    pass: '**********'
  }
});

var mailOptions = {
  from: '*********@gmail.com',
  to: '********.********@gmail.com',
  subject: 'Sending Email using Node.js',
  text: 'That was easy!'
};

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

Thanks.

mmvsbg
  • 3,570
  • 17
  • 52
  • 73
  • No. You have to understand how the control flow of your application is working. Your sendMail method will exit once e-mail is sent/ or errored. And that's it. In order to do what you want to do, you have to have a web application that listens to the responses(http requests) with some persistence layer to keep track of links and clicks. Also, consider about the security aspects. Probably you want to have some time-bound hashes to be part of the links. – Vladimir M Feb 12 '18 at 09:49
  • Ok, so, can i make my program in pause, and wait for a keyword for unlock it ? By example : i send a word by email ("Hello") and, until i dont say this word by voice, my program is in pause, when i say it, my program running – Victor Attila Breelle Feb 12 '18 at 10:06
  • not exactly. check the description of node.js tag. EVENT-BASED, NON-BLOCKING, ASYNC I/O. You have to understaqnd the meaning of these concepts. pausing a program means that you are blocking and that you are not async and I'd hardly call it event-based. In other words, sending an e-mail and receiving an answer are 2 different events. And they should be processed as different flows. – Vladimir M Feb 12 '18 at 10:12
  • Ok, i'll check that :) Thanks – Victor Attila Breelle Feb 12 '18 at 10:15

2 Answers2

1

You have a lot of things you need to think about when designing this - nevermind actually coding it.

  • Somehow you need to get the user's address in the first place. Google Home (and the Actions on Google platform) don't have a way to give this to you, and asking the user for their info is a bad UX.

  • One way you can get their address is through Account Linking, which lets you link their Assistant account to an account in your system. This won't give you the address directly, but since they have to log in through your website first, you can either use Google Login (and thus get their profile info) or ask them for it as part of your account process.

  • Once you have their address - you want to verify it. There are a ton of suggestions on the web about how to correctly do double-opt-in. Make sure you follow them. There are node modules that will help you do this as well - you don't need to write your own.

  • Coding this securely is not something to be taken lightly. Doing it wrong lets you become a spam relay. Doing it not-quite-right may just have you considered as spam by the email providers.

Prisoner
  • 49,922
  • 7
  • 53
  • 105
0

All you have to do is Define System so that from that E-mail box e-mail will be sent. Example, you can add your Gmail account and password. Add this code just in Server.js just below the var app=express() line.

var smtpTransport = nodemailer.createTransport({
    service: "gmail",
    host: "smtp.gmail.com",
    auth: {
        user: "",
        pass: ""
    }
});
Ronan Quillevere
  • 3,699
  • 1
  • 29
  • 44