Skip to content

Instantly share code, notes, and snippets.

@louh
Last active July 8, 2017 04:50
Show Gist options
  • Save louh/45792fa5b6844506c5097e50d615c37b to your computer and use it in GitHub Desktop.
Save louh/45792fa5b6844506c5097e50d615c37b to your computer and use it in GitHub Desktop.
SendGrid's new client library is way worse.
var sendgrid = require('sendgrid')(process.env.SENDGRID_USERNAME, process.env.SENDGRID_PASSWORD)
sendgrid.send({
to: 'test@example.com',
from: 'test@example.com',
subject: 'Hello World from the SendGrid Node.js Library',
text: 'some text here'
}, function (err, json) {
if (err) {
res.status(500).json({ msg: 'Could not send feedback.' })
return
}
res.status(202).json({ msg: 'Feedback accepted.' })
})
var helper = require('sendgrid').mail
from_email = new helper.Email("test@example.com")
to_email = new helper.Email("test@example.com")
subject = "Hello World from the SendGrid Node.js Library"
content = new helper.Content("text/plain", "some text here")
mail = new helper.Mail(from_email, subject, to_email, content)
var sg = require('sendgrid').SendGrid(process.env.SENDGRID_API_KEY)
var requestBody = mail.toJSON()
var request = sg.emptyRequest()
request.method = 'POST'
request.path = '/v3/mail/send'
request.body = requestBody
sg.send(request, function (response) {
console.log(response.statusCode)
console.log(response.body)
console.log(response.headers)
})
@krunkosaurus
Copy link

Just upgraded to the new Sendgrid node library and have to agree - it's Java-hell.

@tscizzle
Copy link

tscizzle commented Jul 8, 2017

I literally googled "sendgrid api way worse"

And I get this gist subtitled "SendGrid's new client library is way worse." hahaha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment