File attachment is 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. The code I'm currently using is as follows. The rk object is simply a namespace.
console.log(call.recording);
var email = new rk.sendgrid.Email({
to: '[email protected]',
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
Looking into this now
Also on StackOverflow. @scottmotte do you mind following up there once you figure out the issue?
http://stackoverflow.com/questions/21921659/using-sendgrid-with-node-js-attachments-are-empty-broken
Hey @namlet I tried the following and was able to get the file in the url you provided to attach and send just fine (code below in case I messed up).
var dotenv = require('dotenv');
dotenv.load();
var sendgrid_username = process.env.SENDGRID_USERNAME;
var sendgrid_password = process.env.SENDGRID_PASSWORD;
var to = process.env.TO;
var sendgrid = require('sendgrid')(sendgrid_username, sendgrid_password);
var email = new sendgrid.Email({
to: to,
from: to,
subject: 'RoadKid Feedback',
text: 'Someone left feedback on your driver.'
});
email.addFile({
filename: 'feedback.mp3',
contentType: 'audio/mpeg',
url: 'http://api.twilio.com/2010-04-01/Accounts/AC4a36110ce12a9cd68a947c87a3a6ab36/Recordings/RE568ecf17e4960105cd131507d49e182f.mp3'
});
sendgrid.send(email, function(err, json) {
if (err) { return console.error(err); }
console.log(json);
});
Could you post your package.json (or the relevant sendgrid part) and also npm ls | grep sendgrid to see what version is installed?
Version:
├─┬ [email protected]
package.json:
{
"name": "RoadKid",
"version": "0.0.1",
"description": "Monitor your teen's driving.",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": { "type":"git" },
"author": "Nathan Loyer",
"license": "BSD",
"dependencies": {
"express": "3.x",
"pg": "2.11.x",
"jade":"1.1.x",
"sequelize": "1.7.x",
"socket.io": "0.9.x",
"sendgrid": "1.0.x",
"twilio": "1.5.x"
}
}
Well, you are correct. When I substitute the actual string it works fine, so I have to assume there is a scoping issue with that object's property. Sorry for the inconvenience.
No worries, glad you figured it out.