0

我有一个 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 中直接使用标签。在我的情况下,它也可以正常工作。

谢谢,

4

2 回答 2

0

Assuming that the sendMail function is working correctly, you'll need to specify the "content type" of the email in the headers. I'm unfamiliar the particular function that you're using but PHP's 'mail' function is formatted similarly and takes a fourth parameter for additional headers.

I imagine it might work something like:

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)
于 2013-04-23T14:22:37.410 回答
0

一种方法是node 上的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
于 2013-04-23T14:18:57.470 回答