sorry for my english
I am using nodemailer and when querying through the api it gives this error:
Error: queryA EREFUSED smtp.gmail.com
at QueryReqWrap.onresolve [as oncomplete] (dns.js:210:19) {
errno: undefined,
code: 'EDNS',
syscall: 'queryA',
hostname: 'smtp.gmail.com',
command: 'CONN'
}
My code:
this.transporter = nodemailer.createTransport({
service: 'gmail'
auth: {
user: mygmail#gmail.com,
pass: mypass,
},
})
UPD: I connected the phone to the Internet instead of my LAN cable, checked, everything worked. There was no error, I connected the LAN back, disconnected the phone, this error appeared again
Make sure that Less secure app access is on in your Gmail account:
Less secure app access > ON
Then fix your code:
this.transporter = nodemailer.createTransport({
service: "gmail",
auth: {
user: email,
pass: password
}
});
You can use the built-in service in the Nodemailer and make your code simpler with this one.
this.transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: mygmail#gmail.com,
pass: mypass,
},
})
Please make sure you have disabled 2-Step verification.
Related
I'm trying to setup ZOHO mail with Nodemailer. The mail is configured correctly and I'm using following code to send the mail, but still getting error in sending mail:
const nodemailer = require('nodemailer');
let from = `Company Name <contact#company.com>`
let transporter = nodemailer.createTransport({
// host: "smtp-mail.gmail.com",
host: 'smtp.zoho.com',
port: 465,
secure: true,
auth: {
user: "contact#company.com",
pass: "mypassword"
}
});
// Mail response to User
const mailResponse = {
from: from,
to: `userName`,
subject: "📞 Thanks For Connecting With Company Name",
html: // mail body
}
try {
await transporter.sendMail(mailResponse);
res.status(200).json({ message: "Message Sent" });
} catch (err) {
res.status(400).json({ message: "Unexpected Error!!! Please try again" });
}
Please let me know how can I fix this issue. i have tried every possible solution given on website.
Try this -
service: "gmail",
host: "smtp.gmail.com",
auth: {
user: "username#company.com",
pass: "yourpassword"
}
At the place of user put your email and in pass but your password or you can get these from env to be safe.
I make sending email with nodemailer library, I am using email office. I already success send email but but it goes to spam email and untrust. can anyone help me?
const mailTransporter = nodemailer.createTransport({
auth: {
user: email_user,
pass: email_pass,
},
host: 'mail.***.co.id',
port: 587,
secure: true,
});
This worked like some days ago but then it stopped. I really don't know what's going on. PS: I am on a Mac and it does not look like it's a firewall issue.
exports.sendEmail = (recipient, subject) => {
const mailTransporter = nodeMailer.createTransport({
service: 'gmail',
host: 'smtp.gmail.com',
port: 465,
secure: true,
auth: {
user: process.env.EMAIL_USER,
pass: process.env.EMAIL_PASS
}
})
const mailOptions = {
from: process.env.EMAIL_USER,
to: recipient,
subject,
html: htmlTemplate(generatePasswordResetLink(),recipient),
}
return mailTransporter.sendMail(mailOptions, (error, success) => {
if (error) {
console.log(error);
return error;
}
return success;
})
The console.log(error); in the code spits this
{ Error: connect ECONNREFUSED 74.125.133.109:465
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1097:14)
errno: 'ECONNREFUSED',
code: 'ESOCKET',
syscall: 'connect',
address: '74.125.133.109',
port: 465,
command: 'CONN' }
And I have tried like everything possible to get it to work. I have also restarted my laptop.
PS:
user: 'a valid gmail account',
pass: 'correct pass for the account'
I try to send an email with Nodemailer and always get the same error:
hostname: 'smtp.zoho.com',
secure: true,
port: 465,
auth: {
user: 'maria#mydomain.my',
pass: 'apppassgenerated'
}
});
I tried too:
service: 'Zoho',
auth: {
user: 'maria#mydomain.my',
pass: 'apppassgenerated'
}
});
I always get: { Error: queryA EREFUSED smtp.zoho.com
at QueryReqWrap.onresolve [as oncomplete] (dns.js:213:19)
errno: 'EREFUSED',
code: 'EDNS',
syscall: 'queryA',
hostname: 'smtp.zoho.com',
command: 'CONN' }
Ok, It was because I was using free plan of Google Functions. If you want to integrate external tools you have to pay 🤷♂️
I know there are many posts like this here, but I couldn't find any information that would solve my issue. So I tried using both nodemailer and emailjs.
I have this code:
This is for nodemailer
var nodemailer = require('nodemailer');
nodemailer.createTestAccount((err, account) => {
if (err) console.log(err);
// create reusable transporter object using the default SMTP transport
var transporter = nodemailer.createTransport({
host: "smtp.Hotmail.com", // Just Hotmail doesn't work either
// port: 587,
auth: {
user: 'xxx#outlook.com',
pass: 'xxx'
}
});
// setup email data with unicode symbols
let mailOptions = {
from: `${req.body.fullName} ${req.body.email}`, // sender address
to: 'alexander.ironside#mygeorgian.ca', // list of receivers
subject: 'Email from SMWDB contact form', // Subject line
html: `<h4>Name: ${req.body.fullName}</h4>
<h4>Company: ${req.body.company}</h4>
<h4>Phone: ${req.body.phone}</h4>
<p>Message: ${req.body.message}</p>`
};
// send mail with defined transport object
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
return console.log(error);
}
console.log('Message sent: %s', info.messageId);
// Preview only available when sending through an Ethereal account
console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));
// Message sent: <b658f8ca-6296-ccf4-8306-87d57a0b4321#example.com>
// Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...
});
});
And this for emailjs
var email = require("emailjs");
var server = email.server.connect({
user: "xxx#outlook.com",
password: "xxx",
host: "smtp-mail.outlook.com",
tls: {ciphers: "SSLv3"}
});
var message = {
text: `Test`,
from: `${req.body.fullName} <${req.body.email}>`,
to: `Alex <alexander.ironside#mygeorgian.ca>`, // list of receivers
// cc: "else <else#your-email.com>",
subject: 'Email from SMWDB contact form', // Subject line
attachment:
[
{
data: `
<h4>Name: ${req.body.fullName}</h4>
<h4>Company: ${req.body.company}</h4>
<h4>Phone: ${req.body.phone}</h4>
<p>Message: ${req.body.message}</p>`
, alternative: true
},
]
};
// send the message and get a callback with an error or details of the message that was sent
server.send(message, (err, message) => {
console.log(err || message);
});
The problem I think is that as host both docs say something like this: smtp.your-email.com, meanwhile all code examples say this: host: "Hotmail". What's the correct way?
I don't really care which package I'm using.
I have to use Hotmail/Yahoo and cannot use Gmail (Too many accounts activated with one phone number)
Now to the errors:
Emailjs throws this:
{ Error: bad response on command '
.': 5.2.0 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message. and then there is a lot of numbers and a callback trace.
Nodemailer throws this:
{ Error: getaddrinfo ENOTFOUND smtp.Hotmail.com smtp.Hotmail.com:587
at errnoException (dns.js:50:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:92:26)
code: 'ECONNECTION',
errno: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'smtp.Hotmail.com',
host: 'smtp.Hotmail.com',
port: 587,
command: 'CONN' }
I used to do this in PHP and have no idea why it's so complicated with Node, but I guess there must be a reason.
I asked a friend to create a Gmail account and it worked right away. If you hit the same problem, don't bother with anything else. Just use Google.
That's the transporter code that worked for me
var transporter = nodemailer.createTransport({
host: "smtp.gmail.com", // hostname
auth: {
user: 'xxx#gmail.com',
pass: 'xxx'
}
});