I try to send email via nodemailer but getting error - TypeError: Cannot read property 'method' of undefined
. It looks like sendMail
function is not defined. Any advise please?
P.S. This code for chatbot hosted on AWS
var nodemailer = require('nodemailer');
var smtpTransport = require('nodemailer-smtp-transport');
module.exports = function someName() {
// create reusable transporter object using the default SMTP transport
var transporter = nodemailer.createTransport(smtpTransport({
service: 'gmail',
auth: {
user: '7384093@gmail.com',
pass: '*******'
}
}))
// setup e-mail data with unicode symbols
var mailOptions = {
from: '"nerd studio" <7384093@gmail.com>', // sender address
to: '7384093@gmail.com', // list of receivers
subject: 'Подтверждение запроса \\ разработак чат-ботов \\ nerd studio', // Subject line
text: 'Добрый день! Вы оставили нашему Валере запрос и мы с радостью подтверждаем его получение. В ближайшее время с вами свяжется наш менелдер', // plaintext body
html: '<b>Добрый день! Вы оставили нашему Валере запрос и мы с радостью подтверждаем его получение. В ближайшее время с вами свяжется наш менелдер</b>' // html body
};
// send mail with defined transport object
transporter.sendMail(mailOptions, function(error, info){
console.log(mailOptions);
console.log(info);
if(error){
return console.log(error);
}
console.log('Message sent: ' + info.response);
});
}
Using Gmail
Using Hotmail
Alternatively, if your account is hotmail instead of outlook, you can use the buil-in hotmail service using the following transport:
Using Zoho
I find solution for , How to send email from="userEmail" to="myEmail"? THIS IS TRICK
You don't need to install npm nodemailer-smtp-transport, only nodemailer is enough to send email to gmail. But first, go to the https://myaccount.google.com/security google account and scroll down and check Allow less secure apps: ON and keep ON. you will send your gmail email. Here, is the full code -
var nodemailer = require('nodemailer'); app.post('/contactform', function (req, res) {
I have nodemailer currently working this way: Create a file config/mail.js:
And then, anytime I want to send an email:
Try this code.First you have to create an app in
Google Cloud Console
andEnable Gmail API
from library.Get the credentials of your app.For that click onCredentials
and in the place ofAuthorized redirect URIs
keep this link https://developers.google.com/oauthplayground and save it.Next in another tab open this link https://developers.google.com/oauthplayground/ click on settings symbol on right side.And make a tick on check box(i.e,Use your own OAuth credentials) after this You have to give your clientId and clientSecret.And at the sametime on left side there is a text box with placeholder likeInput Your Own Scopes
there keep this link https://mail.google.com/ and click on Authorize APIs then click onExchange authorization code for tokens
then you will get yourrefreshToken
andaccessToken
keep these two in your code.Hope this hepls for you.