gpt4 book ai didi

nodemailer authentication issues(nodemailer身份验证问题)

转载 作者:bug小助手 更新时间:2023-10-22 13:50:51 28 4
gpt4 key购买 nike



this is the first time i am using nodemailer, and i am having issues authenticating my details with godaddy.

这是我第一次使用nodemailer,我在使用godaddy验证我的详细信息时遇到了问题。


This is the function i have in my node.js/express backend router:

这是我在node.js/express后端路由器中的功能:


const router = require("express").Router();
const nodemailer = require("nodemailer");
const simplesmtp = require("simplesmtp");
const MailParser = require("mailparser").MailParser;
const imaps = require("imap-simple");

// Function to send an email
function sendEmail(data) {
// SMTP configuration
const smtpTransport = nodemailer.createTransport({
host: "smtp.office365.com",
port: 587,
secure: true,
tls: {
ciphers: "SSLv3",
minVersion: "TLSv1.2", // Use TLS 1.2 or higher
},
auth: {
user: "[email protected]",
pass: "mypassword",
},
});

const mailOptions = {
to: data.email,
from: "[email protected]",
subject: "Test Email",
text: data.message,
};

smtpTransport.sendMail(mailOptions, (error, info) => {
if (error) {
console.log(`Error sending email: ${error}`);
} else {
console.log(`Email sent: ${info.response}`);
}
smtpTransport.close();
});
}

// Function to create the SMTP server for receiving emails
function createSMTPServer() {
// Create a simple SMTP server to receive emails
const server = simplesmtp.createServer({
debug: false,
});

server.on("startData", (connection) => {
console.log(`Message from: ${connection.from}`);
console.log(`Message to: ${connection.to}`);
connection.saveStream = new MailParser();

connection.saveStream.on("end", (mail) => {
console.log("Received email:");
console.log(`Subject: ${mail.subject}`);
console.log(`From: ${mail.from.text}`);
console.log(`To: ${mail.to.text}`);
console.log(`Body: ${mail.text}`);
});

connection.pipe(connection.saveStream);
});

server.listen(25);
}

// Function to connect to the IMAP server and start listening for emails
function connectToIMAPServer() {
// IMAP configuration
const imapConfig = {
imap: {
user: "[email protected]", // Replace with your Office365 email address
password: "mypassword", // Replace with your Office365 email password
host: "outlook.office365.com",
port: 993,
tls: true, // Use TLS encryption
authTimeout: 10000, // Set an authentication timeout
},
onmail: (numNewMsgs) => {
console.log(`You have ${numNewMsgs} new email(s).`);
},
};

// Connect to the IMAP server and start listening for emails
imaps
.connect(imapConfig)
.then((connection) => {
return connection.openBox("INBOX").then(() => {
console.log("Connected to IMAP server");
});
})
.catch((err) => {
console.error(`Error connecting to IMAP server: ${err}`);
});
}

// Handle the /contact route
router.post("/contact", (req, res) => {
let data = req.body;
console.log(data);
if (
data.name.length === 0 ||
data.email.length === 0 ||
data.message.length === 0
) {
return res.json({ msg: "Please fill out all the fields" });
}

// Send an email
sendEmail(data);

// You can also start the SMTP server for receiving emails if needed
// createSMTPServer();

// Connect to the IMAP server and start listening for emails
connectToIMAPServer();

res.json({ msg: "Email sent and listening for incoming emails" });
});

module.exports = router;


of course i have my real email and password in there.

当然,我有我的真实电子邮件和密码在那里。


and this is the error message i am receiving in the VSCode console:
[0] Error sending email: Error: 34400000:error:0A00010B:SSL routines:ssl3_get_record:wrong version number:c:\ws\deps\openssl\openssl\ssl\record\ssl3_record.c:355:
I have tried other versions of this code, and i have only received other error messages such as failed to authenticate. I am using the normal password I use to login to my godaddy/office365 email address.

这是我在VSCode控制台中收到的错误消息:[0]发送电子邮件时出错:错误:34400000:错误:0A00010B:SSL例程:ssl3_get_record:错误的版本号:c:\ws\deps\openssl\openssl\SSL\record\ssl3_record。c:355:我尝试过此代码的其他版本,只收到过其他错误消息,如身份验证失败。我使用普通密码登录我的godaddy/office365电子邮件地址。


I spoke to goDaddy, and they gave me the config settings i need -
Username: Email address
Password: Email password Incoming settings
Server name:
outlook.office365.com (POP/IMAP)Port:
POP: 995 with SSL selected
IMAP: 993 with SSL selectedEncryption method:
TLS (POP/IMAP) Outgoing settings
Server name:
smtp.office365.comPort:
587Encryption method:
STARTTLS

我和goDaddy谈过了,他们给了我所需的配置设置-用户名:电子邮件地址密码:电子邮件密码传入设置服务器名称:outlook.office365.com(POP/IMAP)端口:POP:995选择SSL IMAP:993选择SSL加密方法:TLS(POP/IIMAP)传出设置服务器名:smtp.office365.comPort:587加密方法:STARTTLS


when i told them that i am still having issues, they said that it is on my end, not their end.

当我告诉他们我仍然有问题时,他们说这是我的问题,而不是他们的问题。


is there anyone who can help me with this?

有人能帮我吗?


UPDATE:
when i used a much simpler version of the function:

更新:当我使用一个简单得多的函数版本时:


const router = require("express").Router();
const nodemailer = require("nodemailer");

router.post("/contact", (req, res) => {
let data = req.body;
if (
data.name.length === 0 ||
data.email.length === 0 ||
data.message.length === 0
) {
return res.json({ msg: "Please fill out all the fields" });
}

let smtpTransport = nodemailer.createTransport({
service: "Godaddy",
host: "smtpout.secureserver.net",
secureConnection: false,
port: 587,
auth: {
user: "[email protected]", // Your GoDaddy email address
pass: "mypassword", // Your GoDaddy email password
},
});

let mailOptions = {
from: data.email,
to: "[email protected]", // Your GoDaddy email address
subject: `Message from ${data.name}`,
html: `
<h3>Informations</h3>
<ul>
<li>Name: ${data.name}</li>
<li>Email: ${data.email}</li>
</ul>
<h3>Message</h3>
<p>${data.message}</p>
`,
};

smtpTransport.sendMail(mailOptions, (err) => {
try {
if (err) {
console.log(err);
return res.status(400).json({ msg: "Failed to send email" });
}
console.log("success");
res.status(200).json({ msg: "Message was sent successfully" });
} catch (err) {
if (err)
return res
.status(500)
.json({ msg: "There was an unexpected server error." });
}
});
});

module.exports = router;

it gave me the following errors:

它给了我以下错误:


[0] Error: Invalid login: 535 Authentication Failed for [email protected]
[0] at SMTPConnection._formatError (C:\Users\Baily\Desktop\nodemailer\nodemailer-form\node_modules\nodemailer\lib\smtp-connection\index.js:790:19)
[0] at SMTPConnection._actionAUTHComplete (C:\Users\Baily\Desktop\nodemailer\nodemailer-form\node_modules\nodemailer\lib\smtp-connection\index.js:1564:34)[0] at SMTPConnection.<anonymous> (C:\Users\Baily\Desktop\nodemailer\nodemailer-form\node_modules\nodemailer\lib\smtp-connection\index.js:546:26)
[0] at SMTPConnection._processResponse (C:\Users\Baily\Desktop\nodemailer\nodemailer-form\node_modules\nodemailer\lib\smtp-connection\index.js:969:20)
[0] at SMTPConnection._onData (C:\Users\Baily\Desktop\nodemailer\nodemailer-form\node_modules\nodemailer\lib\smtp-connection\index.js:755:14)
[0] at SMTPConnection._onSocketData (C:\Users\Baily\Desktop\nodemailer\nodemailer-form\node_modules\nodemailer\lib\smtp-connection\index.js:193:44)
[0] at TLSSocket.emit (node:events:513:28)
[0] at addChunk (node:internal/streams/readable:324:12)
[0] at readableAddChunk (node:internal/streams/readable:297:9)
[0] at Readable.push (node:internal/streams/readable:234:10) {
[0] code: 'EAUTH',
[0] response: '535 Authentication Failed for [email protected]',
[0] responseCode: 535,
[0] command: 'AUTH PLAIN'
[0] }

then it started giving me this error:

然后它开始给我这个错误:


[0] Error: Mail command failed: 550 User [email protected] has exceeded its 24-hour sending limit. Messages to 5 recipients out of 5 allowed have been sent. Relay quota will reset in 13.69 hours.
[0] at SMTPConnection._formatError (C:\Users\Baily\Desktop\nodemailer\nodemailer-form\node_modules\nodemailer\lib\smtp-connection\index.js:790:19)
[0] at SMTPConnection._actionMAIL (C:\Users\Baily\Desktop\nodemailer\nodemailer-form\node_modules\nodemailer\lib\smtp-connection\index.js:1594:34)
[0] at SMTPConnection.<anonymous> (C:\Users\Baily\Desktop\nodemailer\nodemailer-form\node_modules\nodemailer\lib\smtp-connection\index.js:1063:18)
[0] at SMTPConnection._processResponse (C:\Users\Baily\Desktop\nodemailer\nodemailer-form\node_modules\nodemailer\lib\smtp-connection\index.js:969:20)
[0] at SMTPConnection._onData (C:\Users\Baily\Desktop\nodemailer\nodemailer-form\node_modules\nodemailer\lib\smtp-connection\index.js:755:14)
[0] at SMTPConnection._onSocketData (C:\Users\Baily\Desktop\nodemailer\nodemailer-form\node_modules\nodemailer\lib\smtp-connection\index.js:193:44)
[0] at TLSSocket.emit (node:events:513:28)
[0] at addChunk (node:internal/streams/readable:324:12)
[0] at readableAddChunk (node:internal/streams/readable:297:9)
[0] at Readable.push (node:internal/streams/readable:234:10) {
[0] code: 'EENVELOPE',
[0] response: '550 User [email protected] has exceeded its 24-hour sending limit. Messages to 5 recipients out of 5 allowed have been sent. Relay
quota will reset in 13.69 hours.',
[0] responseCode: 550,
[0] command: 'MAIL FROM'
[0] }

even though i have not succeeded in sending / receiving a single email like this.
it is also weird that there is a limit of only 5 emails in every 24 hours....

尽管我还没有成功地发送/接收到一封这样的电子邮件。同样奇怪的是,每24小时只有5封电子邮件的限制。。。。


更多回答

I can notice it's complaining from using 'ssl' do you actually need it? try commenting it or use lower version. Or even commenting all 'tls' data. I believe if you don't use tls no need to be secured.

我注意到它在抱怨使用“ssl”,你真的需要它吗?请尝试对其进行注释或使用较低版本。甚至对所有的“tl”数据进行注释。我相信,如果你不使用tls,就没有必要被保护。

when i tried doing this, i got this error Error sending email: Error: Invalid login: 535 5.7.139 Authentication unsuccessful, the request did not meet the criteria to be authenticated successfully. Contact your administrator. [AM0PR06CA0074.eurprd06.prod.outlook.com 2023-09-10T18:41:09.408Z 08DBAF90A9662C63]

当我尝试这样做时,我收到了以下错误发送电子邮件时出错:错误:无效登录:535 5.7.139验证不成功,请求不符合成功验证的标准。请与管理员联系。[AM0PR06CA0074.eurprd06.prod.outlook.com 2023-09-10T18:09.408Z 08DBAF90A9662C63]

优秀答案推荐

when i face this problem i was using google account (Gmail serves ) and i solve it by enable 2step verification

当我遇到这个问题时,我正在使用谷歌帐户(Gmail服务),我通过启用2步验证来解决它


also you can read that
https://www.courier.com/error-solutions/535-authentication-failed-nodemailer/

你也可以读到https://www.courier.com/error-solutions/535-authentication-failed-nodemailer/



Do you have any 2FA authentication ? Maybe u need to configure ur mail for 3rd party software login permission.

你有2FA身份验证吗?也许你需要为第三方软件登录权限配置你的邮件。



To solve this problem you should consider using an app password for third-party services with your Google account, follow these steps:

要解决此问题,您应该考虑使用谷歌帐户为第三方服务使用应用程序密码,请执行以下步骤:



  1. Enable Two-Factor Authentication:



    • Go to your Google Account settings.

    • Navigate to the security section and enable Two-Factor Authentication.



  2. Create an App Password:



    • In the Google Account settings, locate the search bar and type "App Password."

    • Select "App Password" from the search results.

    • Create an app password for your email account. This password will be a hexadecimal code.



  3. Using the App Password with Nodemailer:



    • You can now use this app password with Nodemailer to authenticate your email.



  4. Separate Email for Authentication and Sending:



    • It's a good practice to use a different email address for authentication (e.g., for logging into your Google Account) and for sending emails. This enhances security and separates concerns(sometimes we are not able to send mail, if we use same email for both).




By following these steps, you'll be able to generate and use an app password for third-party services like Nodemailer

通过以下步骤,您将能够为Nodemailer等第三方服务生成并使用应用程序密码


更多回答

when i spoke to godaddy they told me I should use my normal password...

当我和godaddy交谈时,他们告诉我应该使用我的普通密码。。。

At least try out the solution before voting negative, i got the same problem when using nodemailer and i resolved it using the app password from my google account

至少在投反对票之前尝试一下这个解决方案,我在使用nodemailer时遇到了同样的问题,我使用谷歌账户中的应用程序密码解决了这个问题

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

您的回答可以通过其他支持信息得到改进。请编辑以添加更多详细信息,如引文或文档,以便其他人可以确认您的答案是正确的。你可以在帮助中心找到更多关于如何写出好答案的信息。

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com