1

我使用 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
    });
}

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

4

3 回答 3

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 ✔&lt;/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,以防用户无法打开超链接。

于 2013-07-15T21:33:15.870 回答
1

某些电子邮件服务不允许指向“localhost”的链接。尝试使用不同的域(如 google.com),看看它是否有效。

于 2015-09-25T19:00:42.087 回答
0

我最近也面临同样的问题。我通过添加协议(https)解决了这个问题。链接应该是:-

<a href='https://localhost/signupconfirmed/"+user.username+"'>Hoàn thành đăng ký tại StockExchange!</a>
于 2021-11-10T07:54:16.183 回答