节点 Mailgun 不附加文件
Node Mailgun Not Attaching Files
我尝试使用以下代码在 Node.js 中使用 Mailgun 发送电子邮件。该代码工作正常,确实发送了电子邮件,但没有附加任何一个文件。
// pdfA and pdfB are both buffers defined earlier
let attachmentA = new mailgun.Attachment({data: pdfA, filename: `pdfA.pdf`, contentType: "application/pdf", knownLength: pdfA.length});
let attachmentB = new mailgun.Attachment({data: pdfB, filename: `pdfB.pdf`, contentType: "application/pdf", knownLength: pdfB.length});
let attachments = [attachmentA, attachmentB];
var data = {
from: "test@test.com",
to: "emailhidden@test.com",
subject: `My Test Email`,
text: 'Hello',
attachments
};
mailgun.messages().send(data, function(error, body) {
console.log(body);
console.log(error);
});
在 NPM readme 中提到了以下内容。
If an attachment object does not satisfy those valid conditions it is
ignored. Multiple attachments can be sent by passing an array in the
attachment parameter. The array elements can be of any one of the
valid types and each one will be handled appropriately.
这是我能找到的 唯一 问题所在。但看起来我的代码满足了所有条件。
有什么调试方法吗?它目前只是默默地失败。它发送了电子邮件,我收到了,但电子邮件中没有附件。
我不是 100% 确定,但我认为您需要使用 attachment
而不是 attachments
。
例如:
var data = {
from: "test@test.com",
to: "emailhidden@test.com",
subject: `My Test Email`,
text: 'Hello',
attachment: attachments
};
否则 mailgun 看不到任何附件,因为它们没有在 attachment
中指定。
我尝试使用以下代码在 Node.js 中使用 Mailgun 发送电子邮件。该代码工作正常,确实发送了电子邮件,但没有附加任何一个文件。
// pdfA and pdfB are both buffers defined earlier
let attachmentA = new mailgun.Attachment({data: pdfA, filename: `pdfA.pdf`, contentType: "application/pdf", knownLength: pdfA.length});
let attachmentB = new mailgun.Attachment({data: pdfB, filename: `pdfB.pdf`, contentType: "application/pdf", knownLength: pdfB.length});
let attachments = [attachmentA, attachmentB];
var data = {
from: "test@test.com",
to: "emailhidden@test.com",
subject: `My Test Email`,
text: 'Hello',
attachments
};
mailgun.messages().send(data, function(error, body) {
console.log(body);
console.log(error);
});
在 NPM readme 中提到了以下内容。
If an attachment object does not satisfy those valid conditions it is ignored. Multiple attachments can be sent by passing an array in the attachment parameter. The array elements can be of any one of the valid types and each one will be handled appropriately.
这是我能找到的 唯一 问题所在。但看起来我的代码满足了所有条件。
有什么调试方法吗?它目前只是默默地失败。它发送了电子邮件,我收到了,但电子邮件中没有附件。
我不是 100% 确定,但我认为您需要使用 attachment
而不是 attachments
。
例如:
var data = {
from: "test@test.com",
to: "emailhidden@test.com",
subject: `My Test Email`,
text: 'Hello',
attachment: attachments
};
否则 mailgun 看不到任何附件,因为它们没有在 attachment
中指定。