I want to send emails from my NodeJs app.
const nodemailer = require('nodemailer');
const senderMail = "myemail@yahoo.com";
const emailTransporter = nodemailer.createTransport({
service: 'yahoo',
auth: {
user: senderMail,
pass: 'mypassword'
}
});
function getMailReceivers(mailReceivers) { // convert the string array to one string
var receivers = "";
for (var i = 0; i < mailReceivers.length; i++) {
receivers += mailReceivers[i];
if (i < mailReceivers.length - 1)
receivers += ", ";
}
return receivers;
}
function getMailOptions(mailReceivers, subj, content) { // set the options and return them
return {
from: senderMail,
to: getMailReceivers(mailReceivers),
subject: subj,
html: content
};
}
module.exports = {
sendHtmlMail: function(mailReceivers, subject, html) { // send an email
emailTransporter.sendMail(getMailOptions(mailReceivers, subject, html), function(error, info) {
if (error) {
throw error;
} else {
console.log(info.response);
}
});
}
};
So I use my correct login . I tested it multiple times. I still get this error message
Error: Invalid login: 535 5.7.0 (#MBR1212) Incorrect username or password.
at SMTPConnection._formatError (...\nodemailer\lib\smtp-connection\index.js:591:19)
at SMTPConnection._actionAUTHComplete (...\nodemailer\lib\smtp-connection\index.js:1320:34)
at SMTPConnection._responseActions.push.str (...\nodemailer\lib\smtp-connection\index.js:356:26)
at SMTPConnection._processResponse (...\nodemailer\lib\smtp-connection\index.js:747:20)
at SMTPConnection._onData (...\nodemailer\lib\smtp-connection\index.js:543:14)
at TLSSocket._socket.on.chunk (...\nodemailer\lib\smtp-connection\index.js:495:47)
at emitOne (events.js:116:13)
at TLSSocket.emit (events.js:211:7)
at addChunk (_stream_readable.js:263:12)
at readableAddChunk (_stream_readable.js:250:11)
There already is a question here but it got no answer yet
nodemailer and yahoo failing to send email
I call my mailer by using this code
mailer.sendHtmlMail(["email1", "email2", "email3"], "Test Email", "<p>Success!</p>");
I recently got my yahoo implementation to work so I thought I'd try to answer your question and share my implementation. You are missing a few fields from your emailTransporter object.
First, you're missing the field. 字段。 For yahoo, that field should be
Yahoo requires the to be 465 or 587. 465 worked for me. 为465或587。465对我有用。
You have the field correct. 字段正确。
Lastly, you need a field. 字段。 Set it to false .
I'm not sure how adding a for loop will effect this but you should try just sending to one email first to make sure it works.
If you'd like, you can add a debugger or logger options. I recommend the logger, it really helped me.
So I would change your emailTransporter object as such:
const senderMail = "myemail@yahoo.com";
const emailTransporter = nodemailer.createTransport({
host: 'smtp.mail.yahoo.com',
port: 465,
service:'yahoo',
secure: false,
auth: {
user: senderMail,
pass: 'mypassword'
},
debug: false,
logger: true . <---highly recommend this one here
});
Side Note 1: Be sure to change your security options to 'less secure apps' in your yahoo account.
Side note 2: While this worked, it took Yahoo almost to send one email! 时间发送一封电子邮件! Not great for development(or production really), I switched to Gmail. I hope this helps.
In yahoo it is not working But in gmail It's Working. For that u need to set up App Password. Follow these steps to create app password
You MUST MUST MUST use APP PASSWORD, NOT personal password, otherwise it will not work.
Usually there is 'how to get app password' for the mail provider OR it is usually located in EMAIL PROGRAMS configuration.
eg for mail.ee you use your EMAIL and App Password is located under: Options -> Oulook, email programs (tab) -> Show Password (assuming you activated it)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.