我使用AWS作为SMTP凭据,这个nestjs模块@nestjs-modules/mailer
在4/5天前工作,但是突然之间,发生了什么
我很肯定我的资历是对的。
Error: Unexpected socket close
at Timeout._onTimeout
node_modules/nodemailer/lib/smtp-transport/index.js:189:31)
at listOnTimeout (internal/timers.js:557:17)
at processTimers (internal/timers.js:500:7)
transport: {
host: process.env.EMAIL_SERVER_HOST,
secure: false,
port: +process.env.EMAIL_SERVER_PORT,
auth: {
user: process.env.EMAIL_SERVER_USER,
pass: process.env.EMAIL_SERVER_PASSWORD,
},
},
defaults: {
from: `${process.env.EMAIL_FROM}`,
},
template: {
dir: join(__dirname, 'templates'),
adapter: new HandlebarsAdapter(),
options: {
strict: true,
},
},
}),
编辑1:它在生产环境上工作,那么为什么它不能在我的本地机器上工作,应用程序是托管在cloud run
上的:(
发布于 2022-03-21 04:22:00
我明白了,这是因为我使用的无线网络。如果我使用我的移动网络,它会正常工作。
发布于 2022-09-22 13:14:45
它工作在当地的环境和生产环境以及。希望能帮上忙。它需要AWS SES密钥和机密、SES SMTP用户和密码以及正确的区域。
import { Module, Global } from '@nestjs/common';
import { MailerModule } from '@nestjs-modules/mailer';
import { HandlebarsAdapter } from '@nestjs-modules/mailer/dist/adapters/handlebars.adapter';
import { MailService } from './mail.service';
import { join } from 'path';
import { ConfigService } from '@nestjs/config';
import * as AWS from 'aws-sdk';
const upperCaseFn = (name: string) => {
return name.toUpperCase();
};
@Global()
@Module({
imports: [
MailerModule.forRootAsync({
useFactory: async (config: ConfigService) => ({
transport: {
SES: new AWS.SES({
region: config.get('AWS_SES_REGION'),
accessKeyId: config.get('AWS_SES_ACCESS_KEY'),
secretAccessKey: config.get('AWS_SES_KEY_SECRET'),
}),
host: config.get('MAIL_HOST'),
port: config.get('MAIL_PORT'),
secure: false,
ignoreTLS:true,
requireTLS:false,
auth: {
user: config.get('MAIL_USERNAME'),
pass: config.get('MAIL_PASSWORD'),
},
debug: true
},
defaults: {
from: `"${config.get('MAIL_FROM_NAME')}" <${config.get(
'MAIL_FROM_ADDRESS',
)}>`,
},
template: {
dir: join(__dirname, '/templates'),
adapter: new HandlebarsAdapter({ upperCase: upperCaseFn }), // or new PugAdapter() or new EjsAdapter()
options: {
strict: true,
},
},
options: {
partials: {
dir: join(__dirname, '/templates/partials'),
options: {
strict: true,
},
},
},
}),
inject: [ConfigService],
}),
],
providers: [MailService],
exports: [MailService],
})
export class MailModule {}
https://stackoverflow.com/questions/71546860
复制相似问题