在我的应用程序中,我有一个 html 表单来添加用户。添加用户后,他们将使用sendmail()
javascript 中的函数获取邮件。一切正常,邮件作为我的标准发送。但我想在我的电子邮件内容中添加用户名。例子:
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>
我的js是这样的:
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); }
});
}
}
我的Json是:
{
"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
}
}