javascript - Nodemailer with Express App won't send email on Button click -
using default set nodemailer, email send our internal mail server fine when app starts code included on app.js page.
//app.js var nodemailer = require('nodemailer'); var transporter = nodemailer.createtransport({ host: 'mail.oursite.com', }); var mailoptions = { from: 'couponrequest@company.com', // sender address to: 'myaddy@company.com', // list of receivers subject: 'hello ✔', // subject line text: 'hello world ✔', // plaintext body html: '<b>hello world ✔</b>' // html body }; // send mail defined transport object transporter.sendmail(mailoptions, function(error, info) { if (error) { return console.log(error); } console.log('message sent: ' + info.response); });
then when switching things around breaks , nothing happens when trying make happen button click.
app.js:
var nodemailer = require('nodemailer'); app.get('/users', routes.users);
users.js
var express = require('express'); var router = express.router(); var nodemailer = require('nodemailer'); /* * post addcoupon request. */ router.post('/addcoupon', function(req, res) { // create reusable transporter object using smtp transport var transporter = nodemailer.createtransport({ host: 'mail.primeshine.com', }); }); module.exports = router;
index.js
var express = require('express'); var router = express.router(); var nodemailer = require('nodemailer'); /* * post addcoupon request. */ router.post('/addcoupon', function(req, res) { // create reusable transporter object using smtp transport var transporter = nodemailer.createtransport({ host: 'mail.primeshine.com', }); }); module.exports = router;
global.js
// add coupon request function addcoupon(event) { event.preventdefault(); var mailoptions = { from: 'couponrequest@company.com', // sender address to: 'myaddy@company.com', // list of receivers subject: 'hello ✔', // subject line text: 'hello world ✔', // plaintext body html: '<b>hello world ✔</b>' // html body }; // send mail defined transport object transporter.sendmail(mailoptions, function(error, info) { if (error) { return console.log(error); } console.log('message sent: ' + info.response); }); };
i tried use relevant code send it. works fine sending info mongodb button when adding user info doesn't submit when try have send email. not sure if have in wrong place or if else wrong... in advance help!
when used nodemailer send emails email account had create transport authentication:
/* define transportation */ var transport = nodemailer.createtransport(smtptransport({ host: 'posteo.de', port: 465, secure: true, auth: { user: 'username', pass: 'password' }, maxconnections: 5, maxmessages: 10 }));
not sure if if necessary in case maybe helps.
Comments
Post a Comment