Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send mailgun using nodemailer-mailgun-transport received connect ECONNREFUSED ::1:587 #1210

Open
tungnt2k opened this issue Jun 26, 2024 · 0 comments

Comments

@tungnt2k
Copy link

I set up this for my backend service:

import * as MailGun from 'nodemailer-mailgun-transport';
import { createTransport } from 'nodemailer';


MailerModule.forRootAsync({
  inject: [ConfigService],
  useFactory: (configService: ConfigService) => {
    console.log({
      api_key: configService.get<string>('MAILGUN_API_KEY'),
      domain: configService.get<string>('MAILGUN_DOMAIN'),
    });

    return {
      transport: createTransport(
        MailGun({
          auth: {
            api_key: configService.get<string>('MAILGUN_API_KEY'),
            domain: configService.get<string>('MAILGUN_DOMAIN'),
          },
        }),
      ),
      defaults: {
        from: '"Incash Option" <[email protected]>',
      },
      template: {
        dir: join(process.cwd(), 'dist', 'libs', 'mail', 'templates'),
        adapter: new HandlebarsAdapter(),
        options: {
          strict: true,
        },
      },
    };
  },
}),

And I will received the response:

    Error: connect ECONNREFUSED ::1:587

If I just used a simple like this. Everything is ok

    const transporter = createTransport(
      MailGun({
        auth: {
          api_key: configService.get<string>('MAILGUN_API_KEY'),
          domain: configService.get<string>('MAILGUN_DOMAIN'),
        },
      }),
    );

   transporter.sendMail({
      from: '"Incash Option" <[email protected]>',
      to: '[email protected]',
      subject: 'Incash Option',
      text: 'Incash Option',
    })

Please let me know what the right way to use the MailGun service is.
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant