> For the complete documentation index, see [llms.txt](https://guilhermesantos.gitbook.io/niro-health/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://guilhermesantos.gitbook.io/niro-health/modules/email.md).

# Email

### Imports

{% tabs %}
{% tab title="Service" %}

```typescript
import { EmailService } from 'niro-health';
```

{% endtab %}

{% tab title="Module" %}

```typescript
import { EmailModule } from 'niro-health';
```

{% endtab %}

{% tab title="Interface" %}

```typescript
import type { IEmailService } from 'niro-health';
```

{% endtab %}
{% endtabs %}

### Environment Variables

{% tabs %}
{% tab title="SMTP" %}

<table><thead><tr><th width="260">name</th><th>description</th></tr></thead><tbody><tr><td><code>SMTP_HOST</code></td><td><code>The SMTP host.</code></td></tr><tr><td><code>SMTP_PORT</code></td><td><code>The SMTP port.</code></td></tr><tr><td><code>SMTP_SECURE</code></td><td><code>The SMTP secure.</code></td></tr><tr><td><code>SMTP_USERNAME</code></td><td><code>The SMTP username.</code></td></tr><tr><td><code>SMTP_PASSWORD</code></td><td><code>The SMTP password.</code></td></tr></tbody></table>

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

{% code title=".env" %}

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

{% endcode %}
{% endtab %}

{% tab title="AWS" %}

<table><thead><tr><th width="260">name</th><th>description</th></tr></thead><tbody><tr><td><code>AWS_ACCESS_KEY_ID</code></td><td><code>The AWS access key id.</code></td></tr><tr><td><code>AWS_SECRET_ACCESS_KEY</code></td><td><code>The AWS secret access key.</code></td></tr></tbody></table>

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

{% code title=".env" %}

```bash
AWS_ACCESS_KEY_ID="AKIA56N57H7KHQVADY55"
AWS_SECRET_ACCESS_KEY="zbVU1PUZFeNbrW0sAP2uG3qRUjT8yD5hqnmhrCr1"
```

{% endcode %}
{% endtab %}
{% endtabs %}

### Method of Use

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

{% code overflow="wrap" %}

```typescript
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 {}
```

{% endcode %}

Injecting the module into our service.

```typescript
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.

<table><thead><tr><th width="311">Interface</th><th>Service</th></tr></thead><tbody><tr><td><code>IConfigurationService</code></td><td><a href="/pages/qVNUf3tpeJXEx7j4GiuW">Link to Service documentation</a></td></tr><tr><td><code>IValidatorRegexpService</code></td><td><a href="/pages/O8NjCtcCgk2uaVu1oyq5">Link to Service documentation</a></td></tr><tr><td><code>IStringExService</code></td><td><a href="/pages/9boqQn1bIK4z9uqBM3n0">Link to Service documentation</a></td></tr><tr><td><code>IAwsCoreService</code></td><td><a href="/pages/R051tJaLwgXMFM18RHjV">Link to Service documentation</a></td></tr><tr><td><code>IAwsConfigurationService</code></td><td><a href="/pages/0brohd55lElyqphTnlly">Link to Service documentation</a></td></tr><tr><td><code>IAwsStsService</code></td><td><a href="/pages/9mbvmC1qDU1pkGOyhBGV">Link to Service documentation</a></td></tr></tbody></table>

### Properties

<table><thead><tr><th width="249.33333333333331">Property</th><th width="127" align="center">Scope</th><th>Description</th></tr></thead><tbody><tr><td><code>_pathTemplates</code></td><td align="center"><code>private</code></td><td><code>The path where the templates are located.</code></td></tr><tr><td><code>_strategy</code></td><td align="center"><code>private</code></td><td><code>The strategy to use to send the email.</code></td></tr><tr><td><code>_from</code></td><td align="center"><code>private</code></td><td><code>The sender of the email.</code></td></tr><tr><td><code>_priority</code></td><td align="center"><code>private</code></td><td><code>The priority of the email.</code></td></tr><tr><td><code>_cc</code></td><td align="center"><code>private</code></td><td><code>The CC (Carbon Copy) of the email.</code></td></tr><tr><td><code>_cco</code></td><td align="center"><code>private</code></td><td><code>The CCO (Carbon Copy Hidden) of the email.</code></td></tr><tr><td><mark style="color:blue;"><strong>get</strong></mark> <code>pathTemplates</code></td><td align="center"><code>public</code></td><td><code>Set the path where the templates are located.</code></td></tr><tr><td><mark style="color:blue;"><strong>get</strong></mark> <code>pathTemplates</code></td><td align="center"><code>public</code></td><td><code>Get the path where the templates are located.</code></td></tr><tr><td><mark style="color:blue;"><strong>set</strong></mark> <code>strategy</code></td><td align="center"><code>public</code></td><td><code>Set the strategy to use to send the email.</code></td></tr><tr><td><mark style="color:blue;"><strong>get</strong></mark> <code>strategy</code></td><td align="center"><code>public</code></td><td><code>Get the strategy to use to send the email.</code></td></tr><tr><td><mark style="color:blue;"><strong>set</strong></mark> <code>from</code></td><td align="center"><code>public</code></td><td><code>Set the sender of the email.</code></td></tr><tr><td><mark style="color:blue;"><strong>get</strong></mark> <code>from</code></td><td align="center"><code>public</code></td><td><code>Get the sender of the email.</code></td></tr><tr><td><mark style="color:blue;"><strong>set</strong></mark> <code>priority</code></td><td align="center"><code>public</code></td><td><code>Set the priority of the email.</code></td></tr><tr><td><mark style="color:blue;"><strong>get</strong></mark> <code>priority</code></td><td align="center"><code>public</code></td><td><code>Get the priority of the email.</code></td></tr><tr><td><mark style="color:blue;"><strong>set</strong></mark> <code>cc</code></td><td align="center"><code>public</code></td><td><code>Set the CC (Carbon Copy) of the email.</code></td></tr><tr><td><mark style="color:blue;"><strong>get</strong></mark> <code>cc</code></td><td align="center"><code>public</code></td><td><code>Get the CC (Carbon Copy) of the email.</code></td></tr><tr><td><mark style="color:blue;"><strong>set</strong></mark> <code>cco</code></td><td align="center"><code>public</code></td><td><code>Set the CCO (Carbon Copy Hidden) of the email.</code></td></tr><tr><td><mark style="color:blue;"><strong>get</strong></mark> <code>cco</code></td><td align="center"><code>public</code></td><td><code>Get the CCO (Carbon Copy Hidden) of the email.</code></td></tr></tbody></table>

### Methods

<table><thead><tr><th width="148.33333333333331">Method</th><th width="129" align="center">Scope</th><th>Description</th></tr></thead><tbody><tr><td><code>resetCC</code></td><td align="center"><code>public</code></td><td><code>Reset list the CC (Carbon Copy) of the email.</code></td></tr><tr><td><code>resetCCO</code></td><td align="center"><code>public</code></td><td><code>Reset list the CCO (Carbon Copy Hidden) of the email.</code></td></tr><tr><td><code>test</code></td><td align="center"><code>public</code></td><td><code>Send a test email.</code></td></tr><tr><td><code>send</code></td><td align="center"><code>public</code></td><td><code>Send an email.</code></td></tr></tbody></table>
