我想使用SendGrid从Azure功能(Javascript)发送带附件的电子邮件。我做了以下
以下是我的Azure功能
module.exports = function (context, myQueueItem) {
var message = {
"personalizations": [ { "to": [ { "email": "testto@test.com" } ] } ],
from: { email: "testfrom@test.com" },
subject: "Azure news",
content: [{
type: 'text/plain',
value: myQueueItem
}]
};
context.done(null, {message});
};
电子邮件正在正确发送。但是我如何添加附件?
答案 0 :(得分:1)
您可以尝试从Sendgrid API获取以下代码段:
const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const msg = {
to: 'recipient@example.org',
from: 'sender@example.org',
subject: 'Hello attachment',
html: '<p>Here’s an attachment for you!</p>',
attachments: [
{
content: 'Some base 64 encoded attachment content',
filename: 'some-attachment.txt',
type: 'plain/text',
disposition: 'attachment',
contentId: 'mytext'
},
],
};
所以在你的背景下:
module.exports = function (context, myQueueItem) {
var message = {
"personalizations": [ { "to": [ { "email": "testto@test.com" } ] } ],
from: { email: "testfrom@test.com" },
subject: "Azure news",
content: [{
type: 'text/plain',
value: myQueueItem
}],
attachments: [
{
content: 'Some base 64 encoded attachment content',
filename: 'some-attachment.txt',
type: 'plain/text',
disposition: 'attachment',
contentId: 'mytext'
},
]
};
context.done(null, {message});
};