简体   繁体   中英

How to get Server ip address to send in mail in nodejs

I am using nodemailer to send mails in nodejs. I am embedding hyperlink to mailbody it is working fine.

My sample mailbody is below

 `This is confirmation mail.\n
                       please click below link to login
              http://${req.headers.host}/login\n\n
              \n`

Observe the scenario, If i open my page as localhost:port it is sending mail with localhost:port when I open with Ipaddress:port then it is sending with Ipaddress:port .

Here comes the my problem I got mail successfully,now I opened my mail in another system and from there I click on the link then it is getting the server can't be reached. This is quite straight forward as the server is running on another machine but I am trying to open in different machine with locahost .

So how can i send the server ip address in that mail. I have also seen about server.address().address but how to use I got confused.

您是否正在使用ExpressJ,可以在nodejs服务器上使用此req.hostname尝试一下,让我知道是否req.ipreq.ip

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM