亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

TypeError - 無效登錄

TypeError - 無效登錄

SMILET 2022-12-02 10:50:45
我寫了一些代碼來在我的 nodejs 應用程序中實現 nodemailer 來發送郵件。我寫了這段代碼:var express = require("express");var router = express.Router();var nodemailer = require("nodemailer");/* GET contact page. */router.get("/", function (req, res, next) {  res.render("contact", { title: "Contact" });});router.post("/send", function (req, res, next) {  var transporter = nodemailer.createTransport({    service: "Gmail",    auth: {      user: "MyEmailHere",      pass: "password",    },    tls: {      rejectUnauthorized: false    }  });  var mailOptions = {    from: "MyEmailHere",    to: "myOtherEmailId",    subject: "Website Submission",    text:      "You have a new submission with the following details...Name: " +      req.body.name +      " Email: " +      req.body.email +      " Message: " +      req.body.message,    html:      "<p> You got a new submission with the following details...</p><ul></ul><li>Name: " +      req.body.name +      "</li><li>Email: " +      req.body.email +      "</li><li>Message: " +      req.body.message +      "</li></ul>",  };  transporter.sendMail(mailOptions, function (error, info) {    if (error) {      console.log(error);      res.redirect("/");    } else {      console.log("Message Sent: " + info.response);    }  });});module.exports = router;但我收到一條錯誤消息:“不接受用戶名和密碼。” 我應該使用我的真實密碼嗎?除了 Gmail 之外,nodemailer 是否還支持 Yahoomail?順便說一下,我仍在學習并處于開發模式。一點幫助?
查看完整描述

2 回答

?
阿晨1998

TA貢獻2037條經驗 獲得超6個贊

當我正確輸入我自己的信息并打開“不太安全的應用程序”時,它完美地工作,請嘗試這種方式


注意(關鍵):確?!安惶踩膽贸绦颉边x項已打開 (如果您不知道如何打開,可以訪問此處)


注意:確保關閉兩步驗證


var express = require("express");

var router = express.Router();

var nodemailer = require("nodemailer");


const myGmailAccount = {

  mail: 'your_gmail_address', // MAIL

  passw: 'your_gmail_password', // PASSW

};


/* GET contact page. */

router.get("/", function (req, res, next) {

  res.render("contact", { title: "Contact" });

});


router.post("/send", function (req, res, next) {

  var transporter = nodemailer.createTransport({

    service: "Gmail",

    auth: {

      user: myGmailAccount.mail,

      pass: myGmailAccount.passw,

    },

    tls: {

      rejectUnauthorized: false

    }

  });


  var mailOptions = {

    from: myGmailAccount.mail,

    to: '[email protected]', // recipient mail

    subject: "Website Submission",

    text:

      "You have a new submission with the following details...Name: " +

      req.body.name +

      " Email: " +

      req.body.email +

      " Message: " +

      req.body.message,

    html:

      "<p> You got a new submission with the following details...</p><ul></ul><li>Name: " +

      req.body.name +

      "</li><li>Email: " +

      req.body.email +

      "</li><li>Message: " +

      req.body.message +

      "</li></ul>",

  };


  transporter.sendMail(mailOptions, function (error, info) {

    if (error) {

      console.log(error);

      res.redirect("/");

    } else {

      console.log("Message Sent: " + info.response);

    }

  });

});


查看完整回答
反對 回復 2022-12-02
?
哆啦的時光機

TA貢獻1779條經驗 獲得超6個贊

是的,您需要輸入您的真實信息,我建議您閱讀此文本。

盡管 Gmail 是開始發送電子郵件的最快方式,但除非您使用 OAuth2 身份驗證,否則它絕不是一個更好的解決方案。Gmail 希望用戶是真正的用戶而不是機器人,因此它會針對每次登錄嘗試運行大量試探法,并阻止任何看起來可疑的內容,以保護用戶免受帳戶劫持企圖。例如,如果您的服務器位于另一個地理位置,您可能會遇到麻煩——在您的開發機器上一切正常,但消息在生產環境中被阻止。

此外,Gmail 提出了“不太安全”應用程序的概念,基本上任何人都可以使用普通密碼登錄 Gmail,因此您最終可能會遇到一個用戶名可以發送郵件的情況(對“不太安全”的應用程序的支持是啟用)但其他被阻止(禁用對“不太安全”的應用程序的支持)。您可以在此處配置您的 Gmail 帳戶以允許安全性較低的應用程序。使用此方法時,請確保還通過完成“Captcha Enable”挑戰來啟用所需的功能。沒有這個,安全性較低的連接可能無法工作。

并確?!鞍踩暂^低的應用程序”選項已打開 如果您不知道如何打開,可以訪問此處

有關更多信息,我建議您查看此頁面


查看完整回答
反對 回復 2022-12-02
  • 2 回答
  • 0 關注
  • 126 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號