我正在尝试使用SendGrid将附件发送到我的电子邮件,在这种情况下,附件的类型为NSData。有没有一种方法可以使用SendGrid发送附件而没有URL或在Parse中保存该图像?我想直接从电话转到带有附件的电子邮件。
目前,电子邮件发送成功,只是没有图像/附件。提前致谢!
Parse.Cloud.define("sendBookRequestEmail", function(request, response) {
var Buffer = require('buffer').Buffer;
var buffer1 = new Buffer(request.params.image);
var b3 = buffer1.toString('base64');
var SendGrid = require("sendgrid");
SendGrid.initialize("username", "password");
SendGrid.sendEmail({
to: "email",
from: request.params.email,
subject: "Requesting book",
text: "Title: " + request.params.title + "\r\n" + "Author: " + request.params.author + "\r\n" + "ISBN: " + request.params.isbn + "\r\n" + "I want to: " + request.params.bookrequest + "\r\n" + "Notes: " + request.params.notes,
attachments: [request.params.image]
}, {
success: function(httpResponse) {
response.success("success");
console.log(httpResponse);
},
error: function(httpResponse) {
console.error(httpResponse);
}
});
});
最佳答案
您传递给sendMail调用的对象的结构不正确。尝试这样的事情:
sendEmail({
to: "email",
from: request.params.email,
subject: "subject",
text: "text",
attachments: [{
content: b3, // 'Some base 64 encoded attachment content'
filename: 'some-attachment.txt',
type: 'plain/text',
disposition: 'attachment',
contentId: 'mytext'
}
],
});