Rishika Rishika - 1 month ago 7
React JSX Question

Sending email to user upon registration in react

I am working on an app which reacts as the base. I have created a registration page and want to send a verification code via email to the user once he registers successfully.I have done the UI part, but have no idea on how to proceed and make it work.I have seen how emails are sent to the user upon registration in PHP, and want to implement the same for in response of registration in my app.

Help in any form would be great!
Thanks!

Answer

Since you are using node, you'll be able to make use of the node mailer package. This allows you to send emails easily straight from node.

https://nodemailer.com/

Have a look at there site for all the details on how to get it setup!

Here is some psuedo code:

User.register(userDetails).then( (createdUser) => {
    // Your user is created
    // Now lets send them an email

    var mailOptions = {
        from: '"Info ?" <yoursite@yoursite.com>', // sender address
        to: userDetails.email, // This can also contain an array of emails
        subject: 'Thanks for registering with <your site name>', 
        // text: 'Hello world ?', // plaintext body
        html: '<b>Some HTML here....</b>' // html body
    };

    // send mail with defined transport object
    transporter.sendMail(mailOptions, function(error, info){
        if(error){
            return console.log(error);
        }
        console.log('Message sent: ' + info.response);
    });
})
Comments