0

when I tried to send an email using nodemailer, after I insert these into my web project, and I get an error "require is not defined". Can I know how to solve it?

           var nodemailer = require('nodemailer');
            var transporter = nodemailer.createTransport({
                service:'gmail',
                auth:{
                    user:'xxx@gmail.com',
                    pass:'xxxxxxx'
                }
            });

            var mailOptions = {
                from:'xxx@gmail.com',
                to: 'xxx@gmail.com',
                subject:'Thanks for using!',
                text:'Thanks!'
            };

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

1 Answers1

0

I am assuming you are trying to do this on the frontend. Nodemailer is a package that is made to be run on a backend node.js server. You do not have node listed for the questions tags so that is why I am assuming this. If this is not the case then check out:

http://requirejs.org/docs/download.html

Add this to your project: https://requirejs.org/docs/release/2.3.5/minified/require.js

and take a look at this http://requirejs.org/docs/api.html

Jotcode
  • 113
  • 1
  • 6