I'm fairly new at this, but having fun playing around with node.js so far.
I'm trying to use a webform to input a gmail email address and password, then use imap to connect to it.
I've inspired my code from http://ift.tt/1kFT5Tw and how to get POST query in express node.js?
var express = require('express');
var app = express();
var Imap = require('imap');
var path = require('path');
var bodyParser = require('body-parser')
app.use( bodyParser.json() ); // to support JSON-encoded bodies
app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
extended: true
}));
inspect = require('util').inspect;
function openInbox(cb) {
imap.openBox('INBOX', false, cb);
}
app.get('/',function(req,res){
res.sendFile(path.join(__dirname, '/index.html'));
});
app.post('/email',function(req,res){
// This part doesn't work... obviously... but this is where I'm stumped!
imap2 = new Imap({
user: req.body.emailuser,
password: req.body.emailpwd,
host: "imap.gmail.com",
port: 993,
tls: true
});
imap2.connect();
});
app.listen(3002,function(){
console.log("Working on port 3002");
});
This is my index.html file:
<html>
<head>
<title>enter email adddress</title>
</head>
<body>
<form id="emailForm" action="/email" method="post">
<input type="text" name="emailuser" id="emailuser">
<input type="password" name="emailpwd" id="emailpwd">
<input type="submit" value="Submit" name="submit">
</form>
</body>
</html>
Any help is appreciated. Thanks so much.
Cheers, Marco
Aucun commentaire:
Enregistrer un commentaire