I have been looking during hours for an answer to my question. I think this question (Send email to localhost smtp server in Node.js) is quite the same but the answer didn't help me.
So I have two VM's which run on Centos7. And I want my VM 1 to send an email to my VM 2. Here is what I have done :
VM 1 : Postfix is installed and configured with it : relayhost = [ip of vm 2]:25
VM 2 : The port 25 is opened. There is the code which listen in port 25 :
'use strict'
const fs = require('fs-extra')
const SMTPServer = require('smtp-server').SMTPServer
const simpleParser = require('mailparser').simpleParser
const date = require('date-and-time')
const builder = require('xmlbuilder') //9.0.4
const say = msg => {
console.log(msg)
}
const server = new SMTPServer({
logger: true,
//secure: true,
//authOptional: true,
//disabledCommands: ['AUTH'],
disabledCommands: ['AUTH', 'STARTTLS'],
// By default only PLAIN and LOGIN are enabled
authMethods: ['PLAIN', 'LOGIN', 'CRAM-MD5'],
onConnect: function(session, callback){
say('hello')
callback()
},
onData: function(stream, session, callback) {
say('received');
callback()
},
})
server.on('error', err => {
say('Error %s', err.message)
})
server.listen(25)
From VM 2 : When I send a mail to locahost with sendmail :
sendmail ldecaudin@localhost < email.txt
, I can see the "hello" and the "received"
From VM 1 : When I send a mail with sendmail (which is automatically relayed by postfix to my VM2) using it :
sendmail ldecaudin@[192.168.56.101] < email.txt
I can only see the "hello", so the connection is running, but I am not able to pass in the "onData" function to get the stream I need.
Also from my VM1, I have a node code which send mails using nodemailer, this code works. When I use this code, I have the same result ("hello" but not "received"), but there are 2 connections instead of one.
So I am totally lost, I tried to add the "onAuth" function, to try many options of "new SMTPServer".
I wonder if this is a problem with a port (but port 25 is open!), or maybe I forgot to put something on Postfix. I don't know.
Can you help me please ?
Thank you a lot by advance !