nodejs smtp-server 电子邮件已发送但未收到 [英] nodejs smtp-server Email gets sent but not received

查看:100
本文介绍了nodejs smtp-server 电子邮件已发送但未收到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

const nodemailer = require('nodemailer');

const SMTPServer = require("smtp-server").SMTPServer;

const server = new SMTPServer({
    onAuth(auth, session, callback) {
        if (auth.username !== "test" || auth.password !== "password") {
            return callback(new Error("Invalid username or password"));
        }
        console.log(mailOptions.text);
        callback(null, {
            user: "test"

        }); // where 123 is the user id or similar property
    }
});

server.on("error", err => {
    console.log("Error %s", err.message);
});

server.listen(26);


var transporter = nodemailer.createTransport({
    host: "MYDOMAINNAME/IP",
    port: 26,
    secure: false,
    auth: {
        user: "test",
        pass: "password"
    },
    tls: {
        rejectUnauthorized: false
    }
});

var mailOptions = {
    from: '"MYSITENAME"<info@MYDOMAIN.com>',
    to: 'ADRESS@TLD.com',
    subject: 'Sending Email using Node.js',
    text: 'That was easy!'
};

transporter.sendMail(mailOptions, function (error, info) {
    if (error) {
        console.log("sendmail" + error);
    } else {
        console.log('Email sent: ' + info.response);
    }
});

输出是:那很简单!已发送电子邮件:250 确定:消息已排队

Output is: That was easy! Email sent: 250 OK: message queued

我只想将带有输入变量的邮件作为文本从我的域名发送到一个普通的 gmail 地址;邮件没有被 gmail/或任何其他地址收到;检查垃圾邮件文件夹;

i just want to send a mail with an input variable as text from my domainname to an normal gmail address; the mail doesent get received by the gmail/ or any other adress; checked the spam folder;

推荐答案

我认为您可能只是排队 smtp-server 实例中的电子邮件,而不是实际上发送.

I think you might simply be queuing the email in your instance of smtp-server and not actually sending it.

smtp-server 的文档以请注意此模块实际上如何不自行发送电子邮件:

The documentation for smtp-server begins with a note about how this module does not actually send emails by itself:

此模块本身不会发送任何电子邮件.smtp-server 允许您使用 SMTP 或 LMTP 协议侦听端口 25/24/465/587 等,仅此而已.您自己的应用程序负责接受消息并将其传送到目的地.

This module does not make any email deliveries by itself. smtp-server allows you to listen on ports 25/24/465/587 etc. using SMTP or LMTP protocol and that’s it. Your own application is responsible of accepting and delivering the message to destination.

您将需要使用 SMTP 客户端模块 smtp-connection 与您的 SMTP 服务器一起发送电子邮件.

You will need to use the SMTP client module smtp-connection in conjunction with your SMTP server to send the email.

您可以在 服务器模块代码中的这一行.

这篇关于nodejs smtp-server 电子邮件已发送但未收到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆