accimeesterlin / nodemailer-examples

Nodemailer examples

Home Page:https://www.youtube.com/playlist?list=PLurIMwd6GdCiv8ZhpqcwqpFM5Ez4JGago

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Form is not posting.

yilmazbingo opened this issue · comments

I even copied and pasted exact code but I get same error:

jquery-3.3.1.min.js:2 POST http://localhost:3000/email 404 (Not Found)

Since I log the ajax requests on console, I also get this:
jquery-3.3.1.min.js:2 XHR failed loading: POST

I tested jquery with different commands and jquery is working fine.
I thought issue might be because of parsing data, so I installed body-parser module didnt help.
Since I saw the ajax error, I was suspecting cross origin policy error. So I added some code to circumvent cross origin policy, I got this error:

:3000/email:1 Failed to load resource: the server responded with a status of 404 (Not Found)

Hey @yilmazbingo,
The server is running on PORT 8080, not 3000. You might need to try to run the example app on http://localhost:8080, and try to send an email again. I updated the README.md and also added some TODO across the codebase so that you can follow along as well. Hope this helps. If you're still running into issues, please share a link to your github repo where the code is hosted, and I can take a look at it. Thanks

Error occursTypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined.

Plz help

const express = require("express");
const router = express.Router();

const nodemailer = require('nodemailer');
const hbs = require('nodemailer-handlebars');
const log = console.log;

router.get("/mail", (req, res) => {

// Step 1
let transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: 'okbozo007@gmail.com',
pass: 'mypass'
}
});

// Step 2
transporter.use('compile', hbs({
viewEngine: 'express-handlebars',
viewPath: './views/'
}));

// Step 3
let mailOptions = {
from: 'md.asif@okbozo.com',
to: 'mdasiff007@gmail.com',
subject: 'Nodemailer - Test',
text: 'Wooohooo it works!!',
template: 'index',
context: {
name: 'Accime Esterling'
} // send extra values to template
};

// Step 4
transporter.sendMail(mailOptions, (err, data) => {
if (err) {
return log('Error occurs' + err);
}
return log('Email sent!!!');
});

});

module.exports = router;