I try to use NodeJS SimpleSMTP. Get source from GIT (NodeJS SimpleSMTP) And try add auth into smtp. My code is:
var SMTP_PORT = 2000;
var smtp = simplesmtp.createServer({debug:true, enableAuthentication:true});
smtp.listen(SMTP_PORT, function(err) {
if (err) console.log(err);
});
smtp.on("authorizeUser", function(connection, username, password, callback){
callback(null, true );
});
smtp.on("startData", function(connection){
console.log("Message from:", connection.from);
console.log("Message to:", connection.to);
});
smtp.on("data", function(connection, chunk){
});
smtp.on("dataReady", function(connection, callback){
console.log("Incoming message saved to /tmp/message.txt");
callback(null, "ABC1"); // ABC1 is the queue id to be advertised to the client
});
And for test I write simple client on Python:
smtpObj = smtplib.SMTP('localhost',2000)
smtpObj.set_debuglevel(1)
smtpObj.login('aaa', 'bbb')
sender="sender@email.com"
toemail = "recv@email.com"
msg = MIMEMultipart('alternative')
msg['Subject'] = "my subj"
msg['From'] = sender
msg['To'] = "recv.email.com"
msg.attach(MIMEText("Hello world!",'html'))
smtpObj.sendmail(sender, [toemail], msg.as_string())
If I comment smtpObj.login('aaa', 'bbb') everything is OK, but I need auth user before send email. For auth in Simple SMTP I should use event authorizeUser and option enableAuthentication:true.
What I do wrong? Why server is not make authentification.
My logs:
Python with show debug info:
send: 'ehlo [127.0.1.1]\r\n'
reply: '250-mypc at your service, [127.0.0.1]\r\n'
reply: '250-8BITMIME\r\n'
reply: '250-ENHANCEDSTATUSCODES\r\n'
reply: '250 STARTTLS\r\n'
reply: retcode (250); Msg: mypc at your service, [127.0.0.1]
8BITMIME
ENHANCEDSTATUSCODES
STARTTLS
Traceback (most recent call last):
File "/home/atlete/work/python/smtptest/src/test.py", line 6, in <module>
server.login("aaa", "bbb")
File "/usr/lib/python2.7/smtplib.py", line 576, in login
raise SMTPException("SMTP AUTH extension not supported by server.")
smtplib.SMTPException: SMTP AUTH extension not supported by server.
NodeJS debug info:
CONNECTION FROM 127.0.0.1
Connection from 127.0.0.1
OUT: "220 mypc ESMTP node.js simplesmtp"
COMMAND: ehlo [127.0.1.1]
OUT: "250-mypc at your service, [127.0.0.1]
250-8BITMIME
250-ENHANCEDSTATUSCODES
250 STARTTLS"
Connection closed to 127.0.0.1
Tough to say without seeing the SMTP logs (set simplesmtp debug:true), but you might check that the python auth method, i.e. LOGIN, matches what you set in the simplesmtp options.