Why the email is not sending

56 views
Skip to first unread message

Ryan Liu

unread,
Dec 6, 2018, 11:21:56 AM12/6/18
to nodejs
I was trying to send a mail through my own smtp server made using smtp-server and I checked my Gmail account and it is not sending.
Here is my smtp server.

const SMTPServer = require("smtp-server").SMTPServer
var fs = require("fs")
const server = new SMTPServer({
    secure: true,
    key: fs.readFileSync("C:/Users/Jerome/smtp.key"),
    cert: fs.readFileSync("C:/Users/Jerome/smtp.cer"),
    size:1024,
    onAuth(auth, session, callback){
        if(auth.username !== 'abc' || auth.password !== 'def'){
            return callback(new Error("Invalid Credentials"));
        }
        callback(null, {user: 123}); // where 123 is the user id or similar property
    },
    onMailFrom(address, session, callback){
        if(address.address !== "nor...@example.com"){
            return callback(new Error("Only nor...@example.com is allowed to send emails"))
        }
        return callback()
    },
    onData(stream, session, callback){
        stream.pipe(process.stdout)
        stream.on('end', () => {
            if (stream.sizeExceeded){
                return callback(new Error('size excedded'))
            }
            return callback(null, "sent")
        })
    }
});
server.listen(465)
server.on('error', function(err){
    console.log(err)
})


Here is the mailing program

const nodemailer = require("nodemailer")
const transport = nodemailer.createTransport({
    host:"localhost",
    port:465,
    secure:true,
    auth: {
        type:"login",
        user:"abc",
        pass:"def"
    },
    tls: {
        rejectUnauthorized: false
    }
})
transport.sendMail({
    from:"nor...@example.com",
    to:"xx...@gmail.com",
    subject:"test",
    text:"test"
}, function(err,info){
    if (err) {
        console.log(err)
    } else {
        console.log(info.response)
    }
})

I ram the smtp server first then the mailing program and the smtp server responds with a 250 sent
What is wrong with the code or what happened?
How should I change the code?

Zlatko

unread,
Dec 7, 2018, 11:45:34 AM12/7/18
to nodejs
Maybe your email got caught in Google's Spam filters. Or one of your email rules deleted it. Maybe obvious, but did you check the spam/trash and such folders?

Also, maybe your actual sender and/or domain combo is weird. E.g. you can set up a domain DNS so that it's only allowed to send emails from a certain IP address or range, or such combinations.

Did you check here?


Zlatko
Reply all
Reply to author
Forward
0 new messages