NodeJS SimpleSMTP服务器不进行身份验证

时间:2013-01-24 13:06:37

标签: node.js smtp authorization

我尝试使用NodeJS SimpleSMTP。从GIT获取资源(NodeJS SimpleSMTP) 并尝试将auth添加到smtp中。我的代码是:

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

为了测试,我在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())

如果我评论 smtpObj.login('aaa','bbb')一切正常,但在发送电子邮件之前我需要auth用户。对于简单SMTP中的身份验证,我应该使用事件 authorizeUser 和选项 enableAuthentication:true

我做错了什么?为什么服务器不进行身份验证。

我的日志:

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调试信息:

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

1 个答案:

答案 0 :(得分:0)

很难说没有看到SMTP日志(设置simplesmtp debug:true),但你可能会检查python auth方法,即LOGIN,与你在simplesmtp选项中设置的匹配。