Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/405.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用node js发送带有输入用户名的电子邮件_Javascript_Html_Json_Node.js - Fatal编程技术网

Javascript 使用node js发送带有输入用户名的电子邮件

Javascript 使用node js发送带有输入用户名的电子邮件,javascript,html,json,node.js,Javascript,Html,Json,Node.js,在我的应用程序中,我有一个html表单来添加用户。添加用户后,他们将使用javascript中的sendmail()函数获取邮件。一切正常,邮件发送是我的标准。但是我想在我的电子邮件内容中添加用户名。 例如: DEAR {USERNAME} (follwed by my message) HTML格式为: <form id="frmAddUser" method="post" action="/add_value" class="form-horizontal"> <

在我的应用程序中,我有一个html表单来添加用户。添加用户后,他们将使用javascript中的
sendmail()
函数获取邮件。一切正常,邮件发送是我的标准。但是我想在我的电子邮件内容中添加用户名。 例如:

DEAR {USERNAME}

(follwed by my message)
HTML格式为:

<form id="frmAddUser" method="post" action="/add_value" class="form-horizontal">
    <div class="control-group">
        <label class="control-label" for="focusedInput">First Name</label>
        <div class="controls">
            <input class="input-xlarge focused" name="txtFirstName" type="text" id="txtFirstName" tabindex="2">
        </div>
    </div>

    <div class="control-group">
        <label class="control-label" for="focusedInput">Last Name</label>
        <div class="controls">
            <input class="input-xlarge focused" name="txtLastName" type="text" id="txtLastName" tabindex="3">
        </div>
    </div>    

    <div class="form-actions">
        <input id="btnSubmit" class="btn btn-primary" value="Add User" onclick="return validateControls(this.form);" type="submit" />
        <input id="btnCancel" class="btn" value="Clear" onclick="document.getElementById('tsubmit').style.display='none'; document.getElementById('loadeux').style.display=''; return true;" type="submit" />
    </div>
</form>

“亲爱的”+username+“,\n”
然后是您的消息?如果您最终多次运行for循环,则for循环中将出现异步问题。请改用async.eachSeries。如果您真的像您一样想要for(i=0;i<1;i++),那么您甚至根本不需要for循环
exports.InsertData = function (req, res) {

    var timestamp = new Date();
    console.log(timestamp);

    obj._id = req.body.txtLoginId,
    obj.name = { f: req.body.txtFirstName, l: req.body.txtLastName },
    obj.email = req.body.txtEmailID,
    obj.MobileNo = req.body.txtmobile,
    obj.Phone_Ext = req.body.txtphone,
    obj.status = req.body.ddSfk,
    obj.isAdmin = req.body.ddlAdmin,
    obj.pwd = generatePassword(8),
    obj.ispwdChange = "False",
    obj.stamps = { 
        ins: timestamp,
        Ins_Ip: ipAddress()
    },
    qry.insert(obj.schUserData, obj, function (err, result) {

        if (err)
            return;

        sendMail(result.email, DbConfig.mailConfig.subject,'Dear{{{user}}}, Welcome to Bigtree Entertainment Pvt Ltd, Your Login details are below: your user name is: {{{user}}} and Password is:  '+ result.pwd)
    });

    res.redirect('/Group');
}


///*----------- User Send Mail ---------------*/

function sendMail(toMailId, subject, body) {

    for (var i = 0; i < 1; i++) {
        email.send({
            ssl: true,
            host: DbConfig.mailConfig.host,                     // smtp server hostname
            port: DbConfig.mailConfig.port,                     // smtp server port
            domain: DbConfig.mailConfig.domain,                 // domain used by client to identify itself to server
            to: toMailId,
            from: DbConfig.mailConfig.from,
            subject: subject,
            reply_to: DbConfig.mailConfig.reply_to,
            body: body,
            authentication: DbConfig.mailConfig.authentication, // auth login is supported; anything else is no auth
            username: DbConfig.mailConfig.username,             // username
            password: DbConfig.mailConfig.password,             // password
            debug: DbConfig.mailConfig.debug                    // log level per message
        },
        function (err, result) {

            if (err) { console.log(err); }
        });
    }
}
{ 
    "mongodbUrl":"mongodb://sfk:sfk@192.168.3.115:27017/BMS",
    "mailConfig" :{

        "host": "smtp.gmail.com",            
        "port": 465,                    
        "domain": "[127.0.0.1]",           
        "from":"example@gmail.com" ,
        "subject":"Please Use this Onetime password to create your own password",
        "reply_to": "example@gmail.com",
        "authentication": "login",       
        "username": "example@gmail.com",         
        "password": "paswd",           
        "debug": true      

        }
}