gpt4 book ai didi

nodemailer authentication issues(节点邮件程序身份验证问题)

转载 作者:bug小助手 更新时间:2023-10-25 19:03:28 27 4
gpt4 key购买 nike



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

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


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:错误版本number:c:\ws\deps\openssl\openssl\ssl\record\ssl3_record.c:355:我已经尝试了此代码的其他版本,但我只收到了其他错误消息,如身份验证失败。我使用的是登录到我的GoPardy/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

我和谷歌爸爸谈过,他们给了我我需要的配置设置-用户名:电子邮件地址密码:电子邮件密码传入设置服务器名称:outlook.office 365.com(POP/IMAP)端口:POP:995,选择了SSL IMAP:993,选择了SSL加密方法:TLS(POP/IMAP)传出设置服务器名称:smtp.office 365.com端口: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’,你真的需要它吗?尝试对其进行注释或使用较低版本。甚至评论所有的“TLS”数据。我相信如果你不使用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:41:09.408Z 08DBAF90A9662C63]

优秀答案推荐

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

当我遇到这个问题时,我正在使用Google帐号(Gmail服务器),我通过启用两步验证解决了这个问题


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...

当我和谷歌爸爸交谈时,他们告诉我应该使用我正常的密码...

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.

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

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