嗨,我正在使用nodejs + gmail API代码发送带有附件的电子邮件。 当我使用小型附件发送电子邮件时,代码可以正常工作。 但是,如果附件大小为6MB左右。 并在发送电子邮件时收到错误消息。
关于如何纠正错误的任何建议。
let mail = new MailComposer({
from : 'me@email.com',
to: inputs["emailID"],
//text: "I hope this works",
html: body,
subject: subj,
textEncoding: "base64",
attachments: [
{
// encoded string as an attachment
filename: attachFileNmae,
content: attachFileContent,
encoding: "base64"
}
]
});
mail.compile().build((error, msg) => {
if (error) return console.log("Error compiling email " + error);
const encodedMessage = Buffer.from(msg)
.toString("base64")
.replace(/\+/g, "-")
.replace(/\//g, "_")
.replace(/=+$/, "");
const gmail = google.gmail({ version: "v1", auth });
gmail.users.messages.send(
{
userId: "me",
resource: {
raw: encodedMessage
}
},
(err, result) => {
if (err)
return console.log(
"NODEMAILER - The API returned an error: " + err
);
console.log(
"NODEMAILER - Sending email reply from server:",
result.data
);
}
);
});
错误
NODEMAILER - The API returned an error: Error: <HTML>
<HEAD>
<TITLE>Request Entity Too Large</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Request Entity Too Large</H1>
<H2>Error 413</H2>
</BODY>
</HTML>