I have a nodemailer functionality on my webpage, which I'm trying to test locally.
In my package.json the version is "nodemailer": "0.7.1"
.
In my routing file I have:
var express = require('express');
var router = express.Router();
var nodemailer = require("nodemailer");
router.get('/', function(req, res, next) {
res.render('home');
});
var smtpTransport = nodemailer.createTransport("SMTP",{
service: "Gmail",
auth: {
user: "example@gmail.com",
pass: "examplePass"
}
});
router.get('/send',function(req,res){
var mailOptions={
from : req.query.from
}
console.log(mailOptions);
smtpTransport.sendMail(mailOptions, function(error, response){
if (error){
console.log(error);
res.end("error");
} else {
console.log("Message sent: " + response.message);
res.end("sent");
}
});
});
module.exports = router;
And in my page I have a script at the bottom which goes:
$(document).ready(function(){
var to,from;
$(".signup").on("click", function(){
from = $("#search").val();
$.get("/send",
{from:from},
function(data){
alert("Thanks :) We'll keep you updated.");
location.reload(true);
});
});
});
I tested some things and when I click the signup button I do get the 'from' field, as well as the alert message, and the page reloads after I approve the alert.
The problem is that the mail doesn't actually arrive to the inbox, and the console msg (firefox) reads simply "syntax error send:1:1"
If I look into the network of the request, I can see that the status code is 200 OK, but the 'response' tab only says "error", without any explanation.
I can't debug this with no information so I hope someone will have an idea why it isn't working. It should work by the way, because I have another site where it works perfectly and and basically did copy-paste from there...
Thanks.