0

我尝试使用 NodeJS SimpleSMTP。从 GIT(NodeJS SimpleSMTP)获取源代码并尝试将身份验证添加到 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')一切正常,但在发送电子邮件之前我需要验证用户。对于简单 SMTP 中的身份验证,我应该使用事件authorizeUser和选项enableAuthentication:true

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

我的日志:

带有显示调试信息的 Python:

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
4

1 回答 1

0

很难说没有看到 SMTP 日志(设置 simplesmtp debug:true),但您可以检查 python auth 方法,即 LOGIN,是否与您在 simplesmtp 选项中设置的内容相匹配。

于 2013-01-24T18:07:44.087 回答