2017-03-26 34 views
0

相关库...nodemailer,req.body问题在使用

var bodyParser    = require('body-parser'), 
    nodemailer    = require('nodemailer'), 
    xoauth2     = require('xoauth2'); 

狂胜......

router.post('/users/contact', function(req, res, next) { 
    res.render('../views/users/contact', { 
    title: 'Contact', 
    layout: 'userLayout.hbs', 
    username: req.user.username, 
    subject: req.body.subject, 
    content: req.body.content 
    }); 
}); 

我转运的选择CFG ...

var options = { 
    from: 'asd', 
    to: req.user.mail, <<--------- works fine under mongodb pulling from db... 
            |-------- 
    subject: req.body.subject, <<__/  those 2 params aren't working. 
    text: req.body.content  << \  i believe transporter isn't the problem. 
            | if i set regular transporter param strings 
            | it works fine... 
};         |-------- 

我需要要知道如何显示请求身体增值模式例如... 一个联系模式,其中用户r等同于输入主题和内容。 表示1个主题的输入和1个textarea的内容。 所以我当前req.body.subject和内容返回EMPTY字段。 thx为你的时间。 :]

+1

如果你问的问题是为什么'req.body.subject'没有一个有效的值,那么我们需要看到更多的相关代码。如果你正在处理一个POST请求,并且你已经正确安装了'body-parser'中间件,'req.body.subject'只会有一个值。如果您所问的问题纯粹是一个nodemailer问题,并且在'options'结构中确实有有效值,那么请显示使用nodemailer的代码,以便人们可以看到您如何调用它以及如何配置它。 – jfriend00

回答

0

使用相关库...

var bodyParser    = require('body-parser'), 
    nodemailer    = require('nodemailer'), 
    xoauth2     = require('xoauth2'); 

狂胜......

router.post('/users/contact', function(req, res, next) { 
    res.render('../views/users/contact', { 
    title: 'Contact', 
    layout: 'userLayout.hbs', 
    username: req.user.username, 
    subject: req.body.subject, 
    content: req.body.content 
    }); 
}); 

我转运的选择CFG ...

var options = { 
    from: 'asd', 
    to: req.user.mail, <<--------- works fine under mongodb pulling from db... 
            |-------- 
    subject: req.body.subject, <<__/  those 2 params aren't working. 
    text: req.body.content  << \  i believe transporter isn't the problem. 
            | if i set regular transporter param strings 
            | it works fine... 
};         |-------- 

我需要知道如何以显示请求身体变形例如... 联系模式whic h用户请求输入主题和内容。 表示1个主题的输入和1个textarea的内容。 所以我当前req.body.subject和内容返回EMPTY字段。 thx为你的时间。 :]