从Node.js使用AUTH NTLM访问SMTP服务器 [英] Accessing SMTP server with AUTH NTLM from Node.js

查看:122
本文介绍了从Node.js使用AUTH NTLM访问SMTP服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用AUTH类型的NTLM访问SMTP服务器.

I'm trying to access a SMTP server with AUTH type of NTLM.

我正在这样使用nodemailer和nodemailer-smtp-transport:

I'm using nodemailer and nodemailer-smtp-transport as such:

var config = require('./config.json');
var nodemailer = require('nodemailer');
var smtpTransport = require('nodemailer-smtp-transport');

var transporter = nodemailer.createTransport(smtpTransport({
    host : config.mailer.host,
    port: config.mailer.port,
    auth: {
        user: config.mailer.username,
        pass: config.mailer.password
    },
    authMethod: 'PLAIN'
}));

但是它不起作用.我得到的错误是:

But it doesn't work. The error I get is:

{ [Error: Invalid login: 504 5.7.4 Unrecognized authentication type]
  code: 'EAUTH',
  response: '504 5.7.4 Unrecognized authentication type',
  responseCode: 504 }

这很有意义,因为如果我通过telnet进入SMTP服务器

Which makes sense, because if I telnet into the SMTP server

ehlo server.domain.net
250-server.domin.net Hello [10.100.10.100]
250-SIZE
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-X-ANONYMOUSTLS
250-AUTH NTLM
250-X-EXPS GSSAPI NTLM
250-8BITMIME
250-BINARYMIME
250-CHUNKING
250-XEXCH50
250 XRDST

然后输入

AUTH PLAIN

我知道

504 5.7.4 Unrecognized authentication type

但是在Node内,如果我将authMethod更改为'NTLM',则会收到一条错误消息

But inside Node, if I change the authMethod to 'NTLM', I get an error that says

{ [Error: Unknown authentication method "NTLM"] code: 'EAUTH' }

我怀疑nodemailer不支持NTLM.如果是这种情况,我该如何连接到需要NTLM身份验证类型的SMTP服务器?

I'm suspecting that nodemailer just doesn't support NTLM. If that's the case, how do I connect to a SMTP server that requires NTLM authentication type?

谢谢

推荐答案

几天前,我的公司遇到了同样的问题.我们考虑的选项是:

My company ran into the same problem a few days ago. The options we considered were:

  1. 要求交换服务器管理员在STARTTLS下启用PLAIN身份验证(这是安全的,并且似乎只涉及勾选两个复选框)
  2. 设置中继到Exchange的本地中继(例如postfix),并使用来自nodemailer的postfix中继
  3. 叉出节点邮件程序并添加NTLM支持

不幸的是,我们在简单的选项(1)和(2)上遇到了政治问题,因此不得不分叉nodemailer.

Unfortunately we hit political issues on the easy options (1) and (2), so had to fork nodemailer.

我尚未发送拉取请求,但分叉位于此处.目前,最简单的使用方法是通过npm直接引用包json中的github项目,例如:

I didn't send a pull request yet, but the fork is here. For the time being the easiest way to use it is via npm by referring directly to the github project in your package json, e.g.:

"dependences": {
  "nodemailer": "steveliles/nodemailer"
}

如果您有兴趣,大部分更改实际上是在一个子项目中( smtp-连接),以及 nodemailer nodemailer-smtp-transport 仅是使我的smtp连接派生叉所必需的.

If you're interested, most of the change was actually in a sub-sub-project (smtp-connection), and the forks of nodemailer, nodemailer-smtp-pool, and nodemailer-smtp-transport are only necessary to get my smtp-connection fork to be picked up.

我们不需要将 NTLM协议实施为

We didn't need to implement the NTLM protocol, as SamDecrock's httpntlm already did the hard work.

它仅针对基于TLS(带有STARTTLS)且没有域或工作站的Exchange 2007进行了测试.

It has only been tested against Exchange 2007 over TLS (with STARTTLS) and no domain or workstation.

如果您的凭据中确实需要域+工作站,只需将它们添加到nodemailer的 options.auth 中,它们就会通过,例如

If you do need domain + workstation in the credentials, just add them to nodemailer's options.auth and they will be passed through, e.g.

var smtpConfig = {
    host: 'ntlm.boo.hoo',
    port: 25,
    auth: {
        domain: 'windows-domain',
        workstation: 'windows-workstation',
        user: 'user@somedomain.com',
        pass: 'pass'
    }
};

我们更不幸的是,我们要连接的交换服务器没有有效的SSL证书,但是幸运的是nodemailer可以通过在 tls:{rejectUnauthorized:false} 中设置选项.

We were even more unlucky in that the exchange server we're connecting to doesn't have a valid SSL certificate, but luckily nodemailer can handle that by setting tls: {rejectUnauthorized: false} in the options.

这篇关于从Node.js使用AUTH NTLM访问SMTP服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆