【问题标题】:Send attachment via SendGrid using Parse Cloud Code Module使用 Parse Cloud 代码模块通过 SendGrid 发送附件
【发布时间】:2016-07-03 08:46:45
【问题描述】:

我正在尝试使用 SendGrid 向我的电子邮件发送附件,在这种情况下,附件是 NSData 类型。有没有办法使用 SendGrid 发送附件,而无需在 Parse 中保存 URL 或该图像?我想从电话直接转到带有附件的电子邮件。

目前邮件发送成功,只是没有图片/附件。提前致谢!

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);
          }
      });
});

【问题讨论】:

    标签: javascript ios parse-platform sendgrid


    【解决方案1】:

    您传递给 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'
       }
     ],
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-05
      • 2023-03-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多