我正在尝试将nodemailer与已部署的Heroku应用程序一起使用,该应用程序具有在heroku中加载的所有配置变量。我使用了这个基本示例,并且能够在本地部署和发送电子邮件:
https://github.com/binhc/react-nodemailer
通过更改此代码:
var transport = {
host: 'smtp.gmail.com',
auth: {
user: creds.USER,
pass: creds.PASS
}
}
为:
var transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
type: 'OAuth2',
user: creds.user,
clientId: creds.googleClientId,
clientSecret: creds.googleClientSecret,
refreshToken: creds.googleRefreshToken
}
});
这是我在heroku中发送的错误:
xhr.js:178 OPTIONS http://localhost:3002/send 0 ()
dispatchXhrRequest @ xhr.js:178
xhrAdapter @ xhr.js:12
dispatchRequest @ dispatchRequest.js:59
Promise.then (async)
request @ Axios.js:51
wrap @ bind.js:9
Book._this.handleSubmit @ book.js:45
apply @ _apply.js:15
baseInvoke @ _baseInvoke.js:21
apply @ _apply.js:16
(anonymous) @ _overRest.js:32
(anonymous) @ Form.js:60
callCallback @ react-dom.development.js:100
invokeGuardedCallbackDev @ react-dom.development.js:138
invokeGuardedCallback @ react-dom.development.js:187
invokeGuardedCallbackAndCatchFirstError @ react-dom.development.js:201
executeDispatch @ react-dom.development.js:466
executeDispatchesInOrder @ react-dom.development.js:488
executeDispatchesAndRelease @ react-dom.development.js:586
executeDispatchesAndReleaseTopLevel @ react-dom.development.js:597
forEachAccumulated @ react-dom.development.js:567
runEventsInBatch @ react-dom.development.js:728
runExtractedEventsInBatch @ react-dom.development.js:737
handleTopLevel @ react-dom.development.js:4201
batchedUpdates @ react-dom.development.js:12537
batchedUpdates @ react-dom.development.js:1939
dispatchEvent @ react-dom.development.js:4282
interactiveUpdates @ react-dom.development.js:12592
interactiveUpdates @ react-dom.development.js:1958
dispatchInteractiveEvent @ react-dom.development.js:4259
createError.js:16 Uncaught (in promise) Error: Network Error
at createError (createError.js:16)
at XMLHttpRequest.handleError (xhr.js:87)
我不明白,因为我有这行代码:
var port = normalizePort(process.env.PORT || '3002');
端口是否应该自动更新为heroku设置的端口?