简体   繁体   English

Nodemailer yahoo 登录不正确

[英]Nodemailer yahoo incorrect login

I want to send emails from my NodeJs app.我想从我的 NodeJs 应用程序发送电子邮件。

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 nodemailer 和 yahoo 无法发送 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. 我最近启用了yahoo实现,因此我想尝试回答您的问题并分享我的实现。 You are missing a few fields from your emailTransporter object. 您缺少emailTransporter对象中的一些字段。

First, you're missing the host field. 首先,您缺少主机字段。 For yahoo, that field should be smtp.mail.yahoo.com 对于yahoo,该字段应为smtp.mail.yahoo.com

Yahoo requires the port to be 465 or 587. 465 worked for me. Yahoo要求端口为465或587。465对我有用。

You have the service field correct. 您的服务字段正确。

Lastly, you need a secure field. 最后,您需要一个安全的字段。 Set it to false . 将其设置为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. 我不确定添加for循环会如何影响此效果,但是您应该尝试先发送至一封电子邮件以确保其正常工作。

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: 因此,我将像这样更改您的emailTransporter对象:

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. 旁注1:请确保将您的yahoo帐户中的安全选项更改为“安全性较低的应用程序”。

Side note 2: While this worked, it took Yahoo almost 7-10 min to send one email! 旁注2:在此方法有效的同时,雅虎花了将近7-10分钟的时间发送一封电子邮件! Not great for development(or production really), I switched to Gmail. 对于开发(或真正的生产)而言不是很好,我改用了Gmail。 I hope this helps. 我希望这有帮助。

In yahoo it is not working But in gmail It's Working.在雅虎它不工作但在 gmail 它的工作。 For that u need to set up App Password.为此,您需要设置应用程序密码。 Follow these steps to create app password请按照以下步骤创建应用密码

  1. Go to your Google Account.转到您的 Google 帐户。
  2. Select Security.选择安全。
  3. Under "Signing in to Google," select App Passwords.在“登录 Google”下,选择应用密码。 You may need to sign in. If you don't have this option, it might be because: 2-Step Verification is not set up for your account.您可能需要登录。如果您没有此选项,可能是因为: 没有为您的帐户设置两步验证。 2-Step Verification is only set up for security keys.两步验证仅为安全密钥设置。 Your account is through work, school, or other organization.您的帐户是通过工作、学校或其他组织。 You turned on Advanced Protection.您开启了高级保护。
  4. At the bottom, choose Select app and choose the app you using and then Select device and choose the device you're using and then Generate.在底部,选择“选择应用”并选择您使用的应用,然后选择“设备”并选择您正在使用的设备,然后“生成”。
  5. Follow the instructions to enter the App Password.按照说明输入应用程序密码。 The App Password is the 16-character code in the yellow bar on your device.应用程序密码是您设备上黄色栏中的 16 个字符的代码。
  6. Tap Done.点击完成。
  7. Then Use that app password in your code See Code Image Hope This will help然后在您的代码中使用该应用程序密码请参阅代码图片希望这会有所帮助

You MUST MUST MUST use APP PASSWORD, NOT personal password, otherwise it will not work.您必须必须必须使用 APP 密码,而不是个人密码,否则将无法使用。

Usually there is 'how to get app password' for the mail provider OR it is usually located in EMAIL PROGRAMS configuration.通常有邮件提供商的“如何获取应用程序密码”,或者它通常位于 EMAIL PROGRAMS 配置中。

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)例如,对于 mail.ee,您使用 EMAIL,App 密码位于:选项 -> Oulook,email 程序(选项卡)-> 显示密码(假设您已激活它)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM