0
我嘗試使用NodeJS SimpleSMTP。從GIT獲取源代碼(NodeJS SimpleSMTP) 並嘗試將auth添加到smtp中。我的代碼是:NodeJS SimpleSMTP服務器不認證
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="[email protected]"
toemail = "[email protected]"
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來顯示調試信息:
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
當我添加選項secureConnection:true, - AUTH工作,但只有當我初始化客戶端,如smtplib.SMTP_SSL('本地主機',2000年) – Evgeniy