繁体   English   中英

Nodemailer:我的前端网站无法通过来自不同 IP 地址的节点邮件发送电子邮件

[英]Nodemailer: My frontend website can't send emails through node mailer from a different IP address

我的前端投资组合有一个电子邮件选项,可以将帖子请求发送到后端的 nodemailer。 我的投资组合已经部署在 firebase 中,我目前正在本地主机服务器上运行后端。

我在笔记本电脑上发送电子邮件时没有遇到任何问题,相同的 IP 地址,而每当我尝试在不同的设备上发送电子邮件时,我都会收到错误消息。

我已经搜索了一天,但找不到可用的解决方案。 关于如何解决这个问题的任何想法?

我的节点邮件配置:


const transporter = nodemailer.createTransport(smtpTransport({
    name: 'domainname',
    host: 'domainname.com',
    port: 443,
    secure: true,
    service: 'gmail',
    auth: {
        user: '*****@gmail.com',
        pass: '******' //Google's less secure apps option enabled.
    },
    tls: {
        // do not fail on invalid certs
        rejectUnauthorized: false,
    }
}))  

发送email失败时,控制台会记录如下错误:

POST http://localhost:4000/api/email/ net::ERR_CONNECTION_REFUSED

TypeError: Failed to fetch
    at main.1ec56b92.js:2:347746
    at c (main.1ec56b92.js:2:168378)
    at Generator._invoke (main.1ec56b92.js:2:168166)
    at Generator.next (main.1ec56b92.js:2:168807)
    at Ft (main.1ec56b92.js:2:332714)
    at i (main.1ec56b92.js:2:347506)
    at main.1ec56b92.js:2:347567
    at new Promise (<anonymous>)
    at main.1ec56b92.js:2:347446
    at main.1ec56b92.js:2:348157

谢谢

正如 Derpirscher 指出的那样,后端的主机被硬编码为 localhost:4000,因此它在我的笔记本电脑上运行但在我的手机上失败了。 我的解决方案是将代码部署到服务器 - 如 Heroku - 并使用其地址连接到 nodemailer API,例如: https://project.herokuapp.com/api/email而不是 https://localhost: 4000/API/电子邮件

暂无
暂无

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

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