我正在尝试建立一个与nodemailer
它使用的传输类型无关的电子邮件系统。
这是我尝试发送电子邮件的方式:
const config = require('config')
const mailerConfig = config.get('mailer')
const transporter = nodemailer.createTransport(mailerConfig.transport)
transporter.sendMail({
from: mailerConfig.from,
to: toEmail,
subject,
text: textBody,
html: htmlBody,
})
这是我的config
文件的样子:
const AWS = require('aws-sdk')
module.exports = {
mailer: {
from: 'test_sender@domain.com',
transport: {
SES: new AWS.SES({
accessKeyId: 'secret-key',
secretAccessKey: 'access-key',
region: 'region',
}),
},
}
}
然后,每当我尝试发送电子邮件时,都会收到以下错误:
error: TypeError: Key must be a buffer
at new Hmac (crypto.js:117:16)
at Object.Hmac (crypto.js:115:12)
at Object.hmac (/Users/sebi/Work/node_modules/aws-sdk/lib/util.js:401:30)
at Object.getSigningKey (/Users/sebi/Work/node_modules/aws-sdk/lib/signers/v4_credentials.js:59:8)
at V4.signature (/Users/sebi/Work/node_modules/aws-sdk/lib/signers/v4.js:97:36)
at V4.authorization (/Users/sebi/Work/node_modules/aws-sdk/lib/signers/v4.js:92:36)
at V4.addAuthorization (/Users/sebi/Work/node_modules/aws-sdk/lib/signers/v4.js:34:12)
at /Users/sebi/Work/node_modules/aws-sdk/lib/event_listeners.js:215:18
at finish (/Users/sebi/Work/node_modules/aws-sdk/lib/config.js:320:7)
at /Users/sebi/Work/node_modules/aws-sdk/lib/config.js:338:9
at /Users/sebi/Work/node_modules/aws-sdk/lib/credentials.js:123:23
at Credentials.refresh (/Users/sebi/Work/node_modules/aws-sdk/lib/credentials.js:194:5)
at Credentials.get (/Users/sebi/Work/node_modules/aws-sdk/lib/credentials.js:121:12)
at getAsyncCredentials (/Users/sebi/Work/node_modules/aws-sdk/lib/config.js:332:24)
at Config.getCredentials (/Users/sebi/Work/node_modules/aws-sdk/lib/config.js:352:9)
at Request.SIGN (/Users/sebi/Work/node_modules/aws-sdk/lib/event_listeners.js:192:22)
请注意,当我AWS.SES()
在发送电子邮件的同一个地方进行实例化时,代码可以正常工作。有什么特别的东西config
可以破坏密码吗?