Skip to content

Instantly share code, notes, and snippets.

@stewartjarod
Created April 11, 2013 16:49
Show Gist options
  • Save stewartjarod/5365074 to your computer and use it in GitHub Desktop.
Save stewartjarod/5365074 to your computer and use it in GitHub Desktop.
Sending email through SendGrid using the SendGrid Node.js Library that includes an attached image using CID. Does not display correctly with Gmail, Yahoo, or Hotmail (such is the nature of CID).
var SendGrid = require('sendgrid').SendGrid;
var sendgrid = new SendGrid('username', 'password');
sendgrid.send({
to: 'test@test.com',
from: 'tester@tester.com',
fromname: 'Test Person',
subject: 'Hello World',
text: 'My first email through SendGrid',
html: 'My first email with SendGrid with html <img src="cid:testme" alt="graphic"/>',
files: [
{
filename: 'sendgrid_logo-8f6ec9845f58c180692f02f6cb6ec894.png', // required only if file.content is used.
url: 'http://sendgrid.com/mkt/assets/sendgrid_logo-8f6ec9845f58c180692f02f6cb6ec894.png', // == One of these three options is required
content: ('testme' | Buffer) //
}
],
}, function(success, message) {
if (!success) {
console.log(message);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment