简体   繁体   English

如何获取服务器IP地址以在Node.js中发送邮件

[英]How to get Server ip address to send in mail in nodejs

I am using nodemailer to send mails in nodejs. 我正在使用nodemailer在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 . 观察的情况下,如果我打开我的页面为localhost:port是发送邮件与localhost:port当我打开Ipaddress:port则发送带有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. 这是我成功收到邮件的问题,现在我在另一个系统中打开了我的邮件,然后从那里单击链接,然后发现server can't be reached.访问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 . 由于服务器正在另一台计算机上运行,​​因此这非常简单,但是我正在尝试使用locahost在另一台计算机上打开。

So how can i send the server ip address in that mail. 因此,我该如何在该邮件中发送服务器IP地址。 I have also seen about server.address().address but how to use I got confused. 我也看到过关于server.address().address但是如何使用server.address().address我感到困惑。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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