使用Javascript通过链接向内容发送电子邮件

时间:2013-04-23 13:56:43

标签: javascript jquery html node.js jsonp

我有一个html表单,其中包含用于添加新用户的输入字段。将用户添加到我的数据库后,使用adduser.js文件中的sendmail()函数将邮件发送给她/他。按照我的标准发送的邮件。但是我想在主体内容中添加超链接。 我的界限是这样的:

  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中使用直接标记。它也适用于我的情况。

谢谢,

2 个答案:

答案 0 :(得分: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 <username@gmail.com>", 
   to:      "someone <someone@gmail.com>, another <another@gmail.com>",
   cc:      "else <else@gmail.com>",
   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

答案 1 :(得分:0)

假设sendMail功能正常运行,您需要在标题中指定电子邮件的“内容类型”。我不熟悉您正在使用的特定功能,但PHP的'mail'功能的格式类似,并为其他标题提供了第四个参数。

我想它可能会起作用:

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)