2015-12-21 109 views
1

我试图使用nodemailerhttps://www.npmjs.com/package/nodemailer)使用本地Windows服务器发送电子邮件,使用SMTP虚拟服务器。NodeJS nodemailer - IIS SMTP虚拟服务器

SMTP虚拟服务器工作正常,我们已经在传统ASP中使用Jmail,将它传递给服务器名称,并发送电子邮件。

var nodemailer = require('nodemailer'); 
var options = { 
    host: 'SERVERNAME' 
}; 
var transporter = nodemailer.createTransport(options); 
var email = { 
    from: '[email protected]', 
    to: '[email protected]', 
    subject: 'hello', 
    text: 'hello world!' 
}; 
var callback = function(err, info){ 
    if (err) { throw err } 
    console.log('sent'); 
} 
transporter.sendMail(email, callback); 

我回来从这个错误是:

Can't send mail - all recipients were rejected: 550 5.7.1 Unable to relay for [email protected]

如果我更新options对象包括auth,像这样:

var options = { 
    host: 'SERVERNAME', 
    auth: { 
     user: '...', 
     pass: '...' 
    } 
}; 

我得到这个错误:

Invalid login: 504 5.7.4 Unrecognized authentication type

如何使用我们的IIS SMTP虚拟服务器,使用nodemailer发送电子邮件..?

回答

0

我仍然不知道为什么上述不起作用,指向nodemailer我们的SMTP虚拟服务器。不过我已经解决了它。

我们的SMTP虚拟服务器设置为使用我们的Office 365帐户,因此我已更新我的nodemailer代码以直接转到Office 365,而不是通过本地服务器。

var options = { 
    host: 'SMTP.office365.com', 
    port: 25, 
    secure: false, 
    ignoreTLS: false, 
    auth: { 
     user: '...', 
     pass: '...' 
    }, 
    tls: { 
     ciphers: 'SSLv3' 
    } 
} 

这是有效的。