app.post('/report/mail', function(req, res) {
const smtpTransport = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 465,
secure: true,
auth: {
type: 'OAuth2',
user: '[email protected]',
clientId: nodemailerConfig.client_id,
clientSecret: nodemailerConfig.client_secret
}
});
const message = {
from: 'soojung <[email protected]>',
to: '[email protected]',
subject: 'Nodemailer test',
html: '<p>mail send test</p>'
};
smtpTransport.sendMail(message, (err, res) => {
if (err) {
console.log(err);
} else {
console.log('Message sent: ', res.message);
}
});
res.send('send mail!');
});
Error: { Error: Missing credentials for "PLAIN" at SMTPConnection._formatError (/Users/soojungchae/Documents/sellymon/igsim/node_modules/nodemailer/lib/smtp-connection/index.js:774:19) at SMTPConnection.login (/Users/soojungchae/Documents/sellymon/igsim/node_modules/nodemailer/lib/smtp-connection/index.js:445:38) at connection.connect (/Users/soojungchae/Documents/sellymon/igsim/node_modules/nodemailer/lib/smtp-transport/index.js:271:32) at SMTPConnection.once (/Users/soojungchae/Documents/sellymon/igsim/node_modules/nodemailer/lib/smtp-connection/index.js:200:17) at Object.onceWrapper (events.js:273:13) at SMTPConnection.emit (events.js:182:13) at SMTPConnection._actionEHLO (/Users/soojungchae/Documents/sellymon/igsim/node_modules/nodemailer/lib/smtp-connection/index.js:1302:14) at SMTPConnection._processResponse (/Users/soojungchae/Documents/sellymon/igsim/node_modules/nodemailer/lib/smtp-connection/index.js:933:20) at SMTPConnection._onData (/Users/soojungchae/Documents/sellymon/igsim/node_modules/nodemailer/lib/smtp-connection/index.js:739:14) at TLSSocket._socket.on.chunk (/Users/soojungchae/Documents/sellymon/igsim/node_modules/nodemailer/lib/smtp-connection/index.js:691:47) at TLSSocket.emit (events.js:182:13) at addChunk (_stream_readable.js:283:12) at readableAddChunk (_stream_readable.js:264:11) at TLSSocket.Readable.push (_stream_readable.js:219:10) at TLSWrap.onStreamRead [as onread] (internal/stream_base_commons.js:94:17) code: 'EAUTH', command: 'API' }
Fix: