I was trying to send a mail through my own smtp server made using 
smtp-server <https://nodemailer.com/extras/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 !== "[email protected]"){
            return callback(new Error("Only [email protected] 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:"[email protected]",
    to:"[email protected]",
    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?

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/f2a9e14f-e480-44b9-9ece-267ea0a9b2cf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to