📝Email

The module that handles the email delivery.

Imports

import { EmailService } from 'niro-health';

Environment Variables

name
description

SMTP_HOST

The SMTP host.

SMTP_PORT

The SMTP port.

SMTP_SECURE

The SMTP secure.

SMTP_USERNAME

The SMTP username.

SMTP_PASSWORD

The SMTP password.

Write .env file with environment variable. Below has an example:

.env
SMTP_HOST="smtp.mail.com"
SMTP_PORT="587"
SMTP_SECURE="false"
SMTP_USERNAME="example@mail.com"
SMTP_PASSWORD="YOUR_SMTP_PASSWORD"

Method of Use

To use this module, you need to inject it into the desired service.

import { Module } from '@nestjs/common';
import {
  EmailService,
  ConfigurationService,
  ValidatorRegexpService,
  StringExService,
  AwsCoreService,
  AwsConfigurationService,
  AwsStsService,
} from 'niro-health';
import { AppController } from './app.controller';
import { AppService } from './app.service';

@Module({
  controllers: [AppController],
  providers: [
    AppService,
    {
      provide: 'IEmailService',
      useClass: EmailService,
    },
    {
      provide: 'IConfigurationService',
      useClass: ConfigurationService,
    },
    {
      provide: 'IValidatorRegexpService',
      useClass: ValidatorRegexpService,
    },
    {
      provide: 'IStringExService',
      useClass: StringExService,
    },
    {
      provide: 'IAwsCoreService',
      useClass: AwsCoreService,
    },
    {
      provide: 'IAwsConfigurationService',
      useClass: AwsConfigurationService,
    },
    {
      provide: 'IAwsStsService',
      useClass: AwsStsService,
    },
  ],
})
export class AppModule {}

Injecting the module into our service.

import { Inject, Injectable } from '@nestjs/common';
import type { IEmailService } from 'niro-health';

@Injectable()
export class AppService {
  constructor(
    @Inject('IEmailService')
    private readonly emailService: IEmailService,
  ) {}

  async test() {
    return await this.emailService.test(
      {
          subject: 'Testing application',
          to: ['niro@health.com'],
      },
      'email-test',
    );
  }
}

With dependencies

You will need to inject the following interfaces.

Interface
Service

Properties

Property
Scope
Description

_pathTemplates

private

The path where the templates are located.

_strategy

private

The strategy to use to send the email.

_from

private

The sender of the email.

_priority

private

The priority of the email.

_cc

private

The CC (Carbon Copy) of the email.

_cco

private

The CCO (Carbon Copy Hidden) of the email.

get pathTemplates

public

Set the path where the templates are located.

get pathTemplates

public

Get the path where the templates are located.

set strategy

public

Set the strategy to use to send the email.

get strategy

public

Get the strategy to use to send the email.

set from

public

Set the sender of the email.

get from

public

Get the sender of the email.

set priority

public

Set the priority of the email.

get priority

public

Get the priority of the email.

set cc

public

Set the CC (Carbon Copy) of the email.

get cc

public

Get the CC (Carbon Copy) of the email.

set cco

public

Set the CCO (Carbon Copy Hidden) of the email.

get cco

public

Get the CCO (Carbon Copy Hidden) of the email.

Methods

Method
Scope
Description

resetCC

public

Reset list the CC (Carbon Copy) of the email.

resetCCO

public

Reset list the CCO (Carbon Copy Hidden) of the email.

test

public

Send a test email.

send

public

Send an email.

Last updated