我有下面這個代碼在本地工作,但當我部署到api.cloudfoundry.com
,根本沒有電子郵件發送。你能幫我理解爲什麼嗎?是否因爲Cloud Foundry阻止某個端口?在Cloud Foundry Node.js上發送Gmail SMTP電子郵件?
var port = (process.env.VMC_APP_PORT || 3000),
host = (process.env.VCAP_APP_HOST || 'localhost'),
http = require('http'),
async = require('async');
var email = require("emailjs");
var server = email.server.connect({
user: "username",
password:"password",
host: "smtp.gmail.com",
ssl: true
});
// send the message and get a callback with an error or details of the message that was sent
http.createServer(function(req, res) {
async.series([
function(callback){
server.send({
text: "This should be <b>BOLD</b>...",
from: "XXX <[email protected]>",
to: "YYY <[email protected]>, ZZZ <[email protected]>",
cc: "",
subject: "emailjs: test HTML body 3",
attachment:
[
{data:"<h1>Big a$$ title</h1><br/>Or maybe this should be <b>BOLD</b> instead!!", alternative:true}
]
}, function(err, message) { console.log(err || message); });
callback(null, 'success');
}
],
function(err, results){
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write(results + '...');
});
}).listen(port, host);
更新1:
的樣子,這是一個Gmail的SMTP問題。我做vmc files myapp logs/stdout.log
而事實證明:
{ [Error: authorization.failed] code: 3, previous: { [Error: bad response on command 'cGludGVyZXN0'] code: 2, smtp: '535-5.7.1 Please log in with your web browser and then try again. Le arn more at\n535 5.7.1 https://support.google.com/mail/bin/answer.py?answer=7875 4 hn9sm22202393qab.8 - gsmtp\r\n' }, smtp: undefined }
我測試的其他SMTP或不同的Gmail帳戶和它的作品。所以這是特定於我正在測試的這個Gmail帳戶。
我再接着這個鏈接https://support.google.com/mail/bin/answer.py?hl=en&answer=78754授權應用
Next step
Sign in using the application you want to authorize access to your account within the next ten minutes. Google will remember the application after it signs in, and will allow it to access your account in the future as long as it uses the correct password.
,並再次嘗試,但仍然登錄沒有運氣。我想我應該到Gmail批准之內收到一封電子郵件,但沒有到目前爲止:(
更新2:
我試着用另一個Gmail帳戶,並通過臺階走到批准的Cloud Foundry的應用程序訪問顯然,對於沒有工作的帳戶,我錯過了「10分鐘窗口」來登錄並批准Cloud Foundry.Gmail從未回來並要求再次批准。小姐錯過了:(
實際上,您可以將主機和端口保留爲localhost:3000,Cloud Foundry將在生產中覆蓋它。 – 2013-02-15 10:47:07
我編輯了更多的細節...謝謝你的日誌主意先生。 Cloud Foundry並不是這裏的錯。 – 2013-02-17 00:07:15