Gà Rù
Gà Rù

Reputation: 291

Node Mailer - Can't click link in Yahoo mail

I use Node Mailer, send mail with a link to click that link confirm the account. I send mail to gmail account, is ok. When i send to yahoo mail, I click to link but nothing happen. This is this code:

var nodemailer = require("nodemailer");

var smtpTransport = nodemailer.createTransport("SMTP",{
    service: "Gmail",
    auth: {
        user: "[email protected]",
        pass: "aaaa"
    }
});

exports.signupConfirm = function(user){
    var mailOptions = {
        from: "admin <[email protected]>", // 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
    });
}

Anyone can help me. Thanks.

Upvotes: 1

Views: 2007

Answers (3)

Ayush Kumar
Ayush Kumar

Reputation: 31

I also face the same issue recently. I Solved the issue by adding the Protocol(https). The link should be:-

<a href='https://localhost/signupconfirmed/"+user.username+"'>Hoàn thành đăng ký tại StockExchange!</a>

Upvotes: 0

Knooper
Knooper

Reputation: 11

Some email services do not allow links that point to "localhost". Try with a different domain (like google.com) and see if it works.

Upvotes: 1

alreadytaken
alreadytaken

Reputation: 2146

I couldn't open links in Yahoo or Thunderbird when sent from Nodemailer, but when I built the link in the variable textLink and then called toString() on that variable, it works:

  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

I have also included a plain text version of the URL at the bottom of the email in case the user can't open the hyperlink.

Upvotes: 3

Related Questions