简体   繁体   中英

How can we build a node api which will send mail to users and will also generate otp for accessing my python microservices

Is there a way to write an email API on nodejs so that an email containing unique auto-generated OTP will be sent to the user in order to access my python micro-services?

Nodemailer is a popular module for sending email inside nodejs. You can find all the details on the website.

Alternatively, you can use 3rd party API for handling transactional emails. In my experience, SendGrid does the job and has a neat API that's easy to implement.

As far as OTP goes, you can use whatever you prefer to generate the password, just never use Math.random because it's not secure. In general, this is how I would structure my app:

  1. Generate OTP using generate-password , or however you see fit
  2. Save the OTP hash to the database (you shouldn't store actual passwords to databases)
  3. Send the email with your link using Nodemailer or a 3rd party transactional email provider
  4. Once user does what he's instructed to do, you compare the OTP hash with the hash you have saved in your database, and react accordingly

If you need any code examples or anything else let me know and I'll edit my answer. Hope this helps:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM