简体   繁体   English

Nodemailer 适用于本地 PC,但不适用于服务器

[英]Nodemailer works on local PC, but not on server

I want to send emails via Gmail (OAuth) from a node.js application with nodemailer.我想通过 Gmail (OAuth) 从带有 nodemailer 的 node.js 应用程序发送电子邮件。 It works perfectly fine on my PC, but if I try it from my Linode server nothing happens.它在我的 PC 上运行良好,但如果我从我的 Linode 服务器尝试它,则没有任何反应。 I don't get an error, it just times out after a few minutes.我没有收到错误,它只是在几分钟后超时。 Firewall is disabled and because the code works on my local machine, I don't know where to start.防火墙被禁用,因为代码在我的本地机器上工作,我不知道从哪里开始。 Maybe someone knows where to start and help me with this issue.也许有人知道从哪里开始并帮助我解决这个问题。

EDIT: You have to contact Linode Support to lift SMTP restrictions:)编辑:您必须联系 Linode 支持以解除 SMTP 限制:)

Thanks a lot!非常感谢!

I've also had issues sending mails from live servers using nodemailer.我也遇到了使用 nodemailer 从实时服务器发送邮件的问题。 I was able to send mails using this block of code:我能够使用这段代码发送邮件:

const nodemailer = require("nodemailer")
const transporter = nodemailer.createTransport({sendmail: true}, {
        from: "no-reply@your-server.com",
        to: "recipient@mail.com",
        subject: "subject"
    })
    var contact;
        transporter.sendMail({html: "<p>mail sent</p>"}, (error, info) => {
        if(error){
                console.log(error)
        }
        else {
                console.log('Email sent: ' + info.response);
        }
})

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

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