首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >nodemailer + nestjs +@nestjs-模块/邮件程序不使用aws ses,提供` error :意外套接字关闭‘错误

nodemailer + nestjs +@nestjs-模块/邮件程序不使用aws ses,提供` error :意外套接字关闭‘错误
EN

Stack Overflow用户
提问于 2022-03-20 12:44:43
回答 2查看 1.1K关注 0票数 0

我使用AWS作为SMTP凭据,这个nestjs模块@nestjs-modules/mailer在4/5天前工作,但是突然之间,发生了什么

我很肯定我的资历是对的。

代码语言:javascript
运行
复制
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)
代码语言:javascript
运行
复制
      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上的:(

EN

回答 2

Stack Overflow用户

发布于 2022-03-21 04:22:00

我明白了,这是因为我使用的无线网络。如果我使用我的移动网络,它会正常工作。

票数 0
EN

Stack Overflow用户

发布于 2022-09-22 13:14:45

它工作在当地的环境和生产环境以及。希望能帮上忙。它需要AWS SES密钥和机密、SES SMTP用户和密码以及正确的区域。

代码语言:javascript
运行
复制
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 {}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71546860

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档