简体   繁体   English

将Sendgrid与node.js一起使用时附件为空/损坏

[英]Using Sendgrid with node.js attachments are empty / broken

Although I have verified that the file does exist and is accessible, the email that is sent attaches an empty file. 尽管我已经确认该文件确实存在并且可以访问,但是发送的电子邮件中附有一个空文件。 I have tried 3 different ways to attach the file, all that return success from the send json response. 我尝试了3种不同的方式来附加文件,所有这些都从send json响应返回成功。 The code I'm currently using is as follows. 我当前使用的代码如下。 The rk object is simply a namespace. rk对象只是一个名称空间。

console.log(call.recording);
var email = new rk.sendgrid.Email({
  to: '4namlet@gmail.com',
  from: rk.config.email_address,
  subject: 'RoadKid Feedback',
  text: 'Someone left feedback on your driver.'//,
  //files: [
  //  {
  //    contentType: 'audio/mpeg',
  //    url: call.recording
  //  }
  //]
});

email.addFile({
  filename: 'feedback.mp3',
  contentType: 'audio/mpeg',
  url: call.recording
});

rk.sendgrid.send(email, function(err, json) {
  if (err) { return console.error(err); }
  console.log(json);
});

An example url value is: 网址值示例是:

http://api.twilio.com/2010-04-01/Accounts/AC4a36110ce12a9cd68a947c87a3a6ab36/Recordings/RE568ecf17e4960105cd131507d49e182f.mp3

Turns out Sendgrid was working fine. 原来Sendgrid运作良好。 (thanks guys for the quick response!) It was a scoping issue. (感谢大家的快速响应!)这是一个范围界定的问题。 For some reason call.recording was getting clobbered or called weird or something. 由于某种原因,call.recording变得混乱或被称为“怪异之物”。 After the console log I added a: var recording_url = call.recording; 在控制台日志之后,我添加了一个: var recording_url = call.recording; and theeen... url: recording_url And it all worked. 还有theeen ... url: recording_url一切都奏效了。 :-/ :-/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM