nodejs smtp-server Email gets sent but not received

孤街醉人 提交于 2019-12-22 23:42:06

问题


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);
    }
});

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

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;


回答1:


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

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

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.

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

You can see where the "250 OK: message queued" response is coming from at this line in the server module's code.



来源:https://stackoverflow.com/questions/54833249/nodejs-smtp-server-email-gets-sent-but-not-received

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!