nest-modules / mailer

📨 A mailer module for Nest framework (node.js)
https://nest-modules.github.io/mailer/
MIT License
845 stars 177 forks source link

How to fix self signed certificate error ? #282

Closed Leccho closed 3 years ago

Leccho commented 4 years ago

I've been using the same config for a while and it just decided to stop working and throw this error:

Error: self signed certificate in certificate chain

I've look for a fix but found nothing conclusive.

issue-label-bot[bot] commented 4 years ago

Issue-Label Bot is automatically applying the label bug to this issue, with a confidence of 0.56. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

Leccho commented 3 years ago

I've fixed it. With this:

MailerModule.forRoot({
  transport: {
    host: 'smtp.example.ca',
    port: 587,
    secure: false,
    auth: {
      user: "noreply@example.com",
      pass: "example",
    },
    tls: {
      rejectUnauthorized: false // this did the trick
    }
  },
  defaults: {
    from: '<noreply@example.com>',
  },
  template: {
    dir: __dirname + '/templates',
    adapter: new HandlebarsAdapter(),
    options: {
      strict: true,
    },
  },
})
arsalansofyrus12 commented 6 months ago

const transport = pino.transport({ target: 'pino/file', options: { destination: process.env.LOG_DESTINATION, mkdir: true, }, });

const logger = pino(transport); @Module({ imports: [ NestjsFormDataModule.config({ storage: MemoryStoredFile }),

TypeOrmModule.forFeature([
  User,
  UserToken,
  UserLogin,
  RefreshToken,
  AddRequest,
  Roles,
  Permissions,
  RolesHasPermissions,
  UserHasRoles,
  UserPayment,
  Visitor,
]),
ConfigModule.forRoot({
  isGlobal: true,
  validationSchema,
}),
MailerModule.forRootAsync({
  useFactory: () => {
    return {
      transport: {
        host: process.env.MAIL_HOST,
        secure: false,
        auth: {
          user: process.env.MAIL_USERNAME,
          pass: process.env.MAIL_PASSWORD,
        },

        tls: {
          rejectUnauthorized: false // This trick is working properly
        },
      },
      defaults: {
        from: process.env.MAIL_FROM,
      },
      template: {
        dir: join(__dirname, 'templates'),
        adapter: new HandlebarsAdapter(),
        options: {
          strict: true,
        },
      },
    };
  },
}),

BullModule.registerQueue({
  name: 'notifications',
}),
LoggerModule.forRoot({
  pinoHttp: {
    logger,
  },
}),
JwtModule.register({
  secret: process.env.JWT_SECRET,
  signOptions: { expiresIn: '3600s' },
}),

], controllers: [AuthController], providers: [ AuthService, LocalStrategy, JwtStrategy, EmailconfirmationService, MailService, UserService, AuthenticationService, S3Service, ], }) export class AuthModule {}