Reputation: 5451
I hosted my Express App on AppFog and I get an issue with EmailJS. (https://github.com/eleith/emailjs)
I recieve the mail but I get this error, in local, I don't see this error:
Error: addListener only takes instances of Function
at SMTPClient.EventEmitter.addListener (events.js:140:11)
at SMTPClientPool.send (/mnt/var/vcap.local/dea/apps/anthonycluse-0-2effab27785dd5296efe3df6844c0c3a/app/node_modules/mailer/lib/node_mailer.js:72:10)
at dispatchMail (/mnt/var/vcap.local/dea/apps/anthonycluse-0-2effab27785dd5296efe3df6844c0c3a/app/node_modules/mailer/lib/node_mailer.js:112:12)
at Object.node_mail [as send] (/mnt/var/vcap.local/dea/apps/anthonycluse-0-2effab27785dd5296efe3df6844c0c3a/app/node_modules/mailer/lib/node_mailer.js:159:5)
at send (/mnt/var/vcap.local/dea/apps/anthonycluse-0-2effab27785dd5296efe3df6844c0c3a/app/routes/contact.js:8:11)
at exports.send (/mnt/var/vcap.local/dea/apps/anthonycluse-0-2effab27785dd5296efe3df6844c0c3a/app/routes/contact.js:30:5)
at callbacks (/mnt/var/vcap.local/dea/apps/anthonycluse-0-2effab27785dd5296efe3df6844c0c3a/app/node_modules/express/lib/router/index.js:161:37)
at param (/mnt/var/vcap.local/dea/apps/anthonycluse-0-2effab27785dd5296efe3df6844c0c3a/app/node_modules/express/lib/router/index.js:135:11)
at pass (/mnt/var/vcap.local/dea/apps/anthonycluse-0-2effab27785dd5296efe3df6844c0c3a/app/node_modules/express/lib/router/index.js:142:5)
at Router._dispatch (/mnt/var/vcap.local/dea/apps/anthonycluse-0-2effab27785dd5296efe3df6844c0c3a/app/node_modules/express/lib/router/index.js:170:5)
My code (works in local):
var Email = require("mailer");
var username = '******';
var password = '******';
var send = function(message, from, subject) {
Email.send({
host : "smtp.sendgrid.net",
port : "****",
domain : "gmail.com",
to : "*****@gmail.com",
from : from,
subject : subject,
body: message,
authentication : "login",
username : username,
password : password
});
}
exports.index = function(req, res) {
res.render('contact', {
emailSuccess: false,
title: "Contact | Anthony Cluse"
});
}
exports.send = function(req, res) {
send(req.body.message, req.body.from, req.body.subject);
res.render('contact', {
emailSuccess: true,
title: "title"
});
}
Using SendGrid:
var SendGrid = require(‘sendgrid’).SendGrid;
var sendgrid = new SendGrid(user, key);
sendgrid.send({
to: ‘[email protected]’,
from: ‘[email protected]’,
subject: ‘Hello World’,
text: ‘My first email through SendGrid’
}, function(success, message) {
if (!success) {
console.log(message);
}
});
Upvotes: 1
Views: 256
Reputation: 11389
You are trying to use the smtp server of Sendgrid. Instead, you should be use the sendgrid module:
var SendGrid = require('sendgrid').SendGrid;
SendGrid.send({
to: '[email protected]',
from: '[email protected]',
subject: 'subject',
text: 'some text;'
}, function(success, message) {
if (!success) {
console.error('sendgrid.send error:', message);
}
});
Upvotes: 1