I'm trying to send an email via a form with SendGrid + Parse Cloud Code Modules. Everything is working fine functionally and the emails are ing through. However, when I look at my logs, I get the following:
Result: ReferenceError: response is not defined
//main.js
var express = require('express');
var sendgrid = require('sendgrid');
sendgrid.initialize("USER", "PASS");
var app = express();
// App configuration section
app.use(express.bodyParser()); // Middleware for reading request body
app.post('/email', function(req, res) {
var name = req.body.name;
var email = req.body.email;
var message = req.body.message;
sendgrid.sendEmail({
to: '[email protected]',
from: email,
subject: 'Message from ' + name + ' via Web',
text: message
}, {
success: function(httpResponse) {
console.log(httpResponse);
response.success("Email sent!");
},
error: function(httpResponse) {
console.error(httpResponse);
response.error("Uh oh, something went wrong");
}
});
});
I'm trying to send an email via a form with SendGrid + Parse Cloud Code Modules. Everything is working fine functionally and the emails are ing through. However, when I look at my logs, I get the following:
Result: ReferenceError: response is not defined
//main.js
var express = require('express');
var sendgrid = require('sendgrid');
sendgrid.initialize("USER", "PASS");
var app = express();
// App configuration section
app.use(express.bodyParser()); // Middleware for reading request body
app.post('/email', function(req, res) {
var name = req.body.name;
var email = req.body.email;
var message = req.body.message;
sendgrid.sendEmail({
to: '[email protected]',
from: email,
subject: 'Message from ' + name + ' via Web',
text: message
}, {
success: function(httpResponse) {
console.log(httpResponse);
response.success("Email sent!");
},
error: function(httpResponse) {
console.error(httpResponse);
response.error("Uh oh, something went wrong");
}
});
});
Share
Improve this question
asked Aug 17, 2015 at 19:35
csakoncsakon
6112 gold badges7 silver badges25 bronze badges
5
-
1
The error is pretty clear to me. You never defined the
response
variable you call. Didn't you meanres
? Orconsole
? Don't forget to fix that both in yoursuccess
handler and yourerror
handler. – blex Commented Aug 17, 2015 at 19:37 - That's what I figured, but when I do that I get the following: Result: TypeError: Object [object Object] has no method 'success' – csakon Commented Aug 17, 2015 at 19:43
-
Where do you want to log these messages?
console.log
is not what you want? I can't find the doc for thesendgrid.sendEmail
function :/ – blex Commented Aug 17, 2015 at 19:49 - @blex - yeah, unfortunately parse isn't fantastic at providing docs for some of this stuff. Here is where I got this from - github./elbuo8/sendgrid-parse – csakon Commented Aug 17, 2015 at 21:04
- Ok, then I think they made a mistake. You should post an issue here, I think it's the best thing you can do to get a proper answer. – blex Commented Aug 17, 2015 at 21:38
1 Answer
Reset to default 1response
is not defined, I think you meant to write
sendgrid.sendEmail({
to: '[email protected]',
from: email,
subject: 'Message from ' + name + ' via Web',
text: message
}, {
success: function(httpResponse) {
console.log(httpResponse);
httpResponse.success("Email sent!");
},
error: function(httpResponse) {
console.error(httpResponse);
httpResponse.error("Uh oh, something went wrong");
}
});
BTW: you should always set strict mode via "use strict" - that would catch undefined variables even faster.