使用解析云代码模块通过 SendGrid 发送附件

Send attachment via SendGrid using Parse Cloud Code Module

本文关键字:SendGrid 模块 代码      更新时间:2023-09-26

我正在尝试使用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'
   }
 ],
});