2013-04-23 122 views
0

我有一个带有输入栏的html表单来添加一个新用户。一旦用户被添加到我的数据库中,邮件将通过我的adduser.js文件中的sendmail()函数发送给她/他。邮件发送按照我的标准。但事情是我想添加一个超链接到正文内容。 我行是这样的:使用Javascript通过电子邮件发送链接内容

sendMail(result.email, DbConfig.mailConfig.subject, "Dear" + " " + req.body.txtFirstName + req.body.txtLastName + ",\n Welcome to, COMPANY NAME " + txt.link('http://www.website.in') + "Your Login details are below: \n User name:" + req.body.txtLoginId + " \n Password:" + result.pwd) 

但它不工作,我的预期。我邮件中的结果是

Dear user. 
Welcome to,COMPANY NAME<ahref="www.website.in"></a>. 

它是这样来的,但链接重定向到指定的目标。我的期望是:

Dear user. 
Welcome to,COMPANY NAME.(on click of company name it redirects to targeted link). 

我该如何做到这一点。我尝试直接在我的JS中使用标记。它也适用于我的情况。

感谢,

+0

没有办法的JavaScript可以发送这样的邮件...你可能使用的是PHP? – 2013-04-23 13:59:36

+0

你不能使用JavaScript发送电子邮件,你需要使用一些服务器端技术,如使用节点的php/java – 2013-04-23 13:59:42

+0

,我有一个json文件 – Aarthi 2013-04-23 14:01:11

回答

0

一种方法是emailjs节点。我已经采取粘贴他们为榜样的自由:

$ npm install emails; 
//app.js: 
var email = require("./path/to/emailjs/email"); 
var server = email.server.connect({ 
    user: "username", 
    password:"password", 
    host: "smtp.gmail.com", 
    ssl:  true 
}); 

var message = { 
    text: "i hope this works", 
    from: "you <[email protected]>", 
    to:  "someone <[email protected]>, another <[email protected]>", 
    cc:  "else <[email protected]>", 
    subject: "testing emailjs", 
    attachment: 
    [ 
     {data:"<html>i <i>hope</i> this works!</html>", alternative:true}, 
     {path:"path/to/file.zip", type:"application/zip", name:"renamed.zip"} 
    ] 
}; 

// send the message and get a callback with an error or details of the message that was sent 
server.send(message, function(err, message) { console.log(err || message); }); 

// you can continue to send more messages with successive calls to 'server.send', 
// they will be queued on the same smtp connection 

// or you can create a new server connection with 'email.server.connect' 
// to asynchronously send individual emails instead of a queue 
0

假设sendmail的功能是否正常工作,你需要指定报头中的电子邮件的“内容类型”。我不熟悉你正在使用的特定函数,但PHP的“邮件”函数格式相似,并为额外的头文件提供了第四个参数。

我想这可能工作是这样的:

var headers = 'Content-type: text/html; charset=iso-8859-1' + "\r\n"; 
var message = "Dear" + " " + req.body.txtFirstName + req.body.txtLastName + ",\n Welcome to, COMPANY NAME " + txt.link('http://www.website.in') + "Your Login details are below: \n User name:" + req.body.txtLoginId + " \n Password:" + result.pwd; 

sendMail(result.email, DbConfig.mailConfig.subject, message, headers)