2013-04-23 148 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)