节点邮件程序 - 无法单击Yahoo邮件中的链接

时间:2013-07-15 08:50:08

标签: node.js nodemailer

我使用Node Mailer,发送带有链接的邮件,点击该链接确认该帐户。我发邮件到gmail帐户,没问题。当我发送到雅虎邮箱时,我点击链接但没有任何反应。 这是这段代码:

var nodemailer = require("nodemailer");

var smtpTransport = nodemailer.createTransport("SMTP",{
    service: "Gmail",
    auth: {
        user: "xxx@gmail.com",
        pass: "aaaa"
    }
});

exports.signupConfirm = function(user){
    var mailOptions = {
        from: "admin <admin@stockexchange.cu8>", // sender address
        to: user.username, // list of receivers
        subject: "Xác nhận đăng ký tại StockExchange", 
        html: "<b>Xin chào "+user.lastname+" "+user.firstname+"!</b>"
            +"<br/>Hãy click vào link dưới đây để hoàn thành đăng ký tại StockExchange:"
            +"<br/><a href='localhost/signupconfirmed/"+user.username+"'>Hoàn thành đăng ký tại StockExchange!</a>"
            +"<br/>Cảm ơn bạn đã đăng ký tại StockExchange!"
    }

    smtpTransport.sendMail(mailOptions, function(error, response){
        if(error){
            console.log(error);
        }else{
            console.log("Message sent: " + response.message);
        }
        //smtpTransport.close(); // shut down the connection pool, no more messages
    });
}

任何人都可以帮助我。感谢。

2 个答案:

答案 0 :(得分:3)

我从Nodemailer发送时无法在Yahoo或Thunderbird中打开链接,但是当我在变量textLink中构建链接然后在该变量上调用toString()时,它可以工作:

  var textLink = "http://" + req.headers.host + "/signup?token=" + data.hashedEmail;
  var mailOptions = {
    from: auth_email, // sender address
    to: data.email, // list of receivers
    subject: "Signup Confirmation ✔", // Subject line
    generateTextFromHTML: true,
    html: '<b>Signup Confirmation ✔</b><br />'
        + 'Your email account is : ' + data.email + '<br />'
        + '<a href=\"'+ textLink.toString() + '\">Click here to activate your account.</a>'
        + '<br />' 
        + '<br /> Text link: ' + textLink

我还在电子邮件底部包含了纯文本版本的URL,以防用户无法打开超链接。

答案 1 :(得分:1)

某些电子邮件服务不允许指向&#34; localhost&#34;的链接。尝试使用其他域名(例如google.com),看看它是否有效。