SendGrid's new client library is way worse.
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)
})
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.' })
})