使用JavaScript通过Parse's Sendgrid模块将图像附加到电子邮件

Attaching image to email through Parse's Sendgrid module using JavaScript

本文关键字:图像 模块 电子邮件 Sendgrid 通过 JavaScript Parse 使用      更新时间:2023-09-26

我想知道是否有人知道如何从Parse的Sendgrid模块发送带有图像的电子邮件(通过这个,我的意思是Facebook的Parse BaaS,而不是Sendgrid的Parse API)。到目前为止,我可以发送电子邮件,但不能附带图片。我尝试了两种不同的方法。一种是发送Base64的电子邮件,但我读到很多电子邮件提供商不支持,因此我不鼓励使用这种方法,因为兼容性是这里的一种问题(虽然不是关键)。我的第二种方法是尝试模仿sendgrid使用cid的过程,但也许我做错了什么,它没有工作

var sendGridInstance = require('sendgrid');
    sendGridInstance.initialize(sendGridUser, sendGridKey);
    sendGridInstance.sendEmail({
         to:endCustomerEmail,
         from: 'test@test.com',
         subject: 'Test subject',
         html: 'My HTML goes here..',
         replyto: 'donotreply@test.com'

上面的代码在CloudCode中调用时都可以工作,并且确实发送电子邮件。但是cid的东西不起作用。

是否有人成功地发送电子邮件w/图像使用sendgrid模块与解析?如果是这样,你能告诉我我错过了什么吗?

所有的帮助是非常感谢!

谢谢!

干杯!

这个模块不支持二进制文件-它调用SendGrid API与application/x-www-form-urlencoded请求,你不能urlencode二进制文件的内容。看看https://github.com/m1gu3l/parse-sendgrid-mailer吧——它调用API,使用multipart/form-data请求,这更适合这种情况。