@brilab-mailer/provider-smtp 0.0.1-beta.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +81 -0
- package/index.d.ts +2 -0
- package/index.d.ts.map +1 -0
- package/index.js +1 -0
- package/lib/smtp-mail.provider.d.ts +22 -0
- package/lib/smtp-mail.provider.d.ts.map +1 -0
- package/lib/smtp-mail.provider.js +39 -0
- package/package.json +47 -0
package/README.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# @brilab-mailer/provider-smtp
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
Generic SMTP provider that supports any SMTP-compatible service:
|
|
5
|
+
- Gmail
|
|
6
|
+
- Outlook
|
|
7
|
+
- SendGrid SMTP
|
|
8
|
+
- Mailgun SMTP
|
|
9
|
+
- Custom SMTP servers
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Environment Variables
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
SMTP_HOST=smtp.example.com
|
|
17
|
+
SMTP_PORT=587
|
|
18
|
+
SMTP_SECURE=false
|
|
19
|
+
SMTP_USER=example
|
|
20
|
+
SMTP_PASS=password
|
|
21
|
+
SMTP_FROM=no-reply@example.com
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pnpm add @brilab-mailer/provider-smtp nodemailer
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Provider Implementation Summary
|
|
35
|
+
|
|
36
|
+
The SMTP provider:
|
|
37
|
+
- creates a nodemailer transport
|
|
38
|
+
- validates credentials
|
|
39
|
+
- sends messages via SMTP protocol
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## Usage in Core
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
MailerModule.register({
|
|
47
|
+
providerClass: SmtpMailProvider,
|
|
48
|
+
templateEngineClass: HandlebarsTemplateEngine,
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## Example Email
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
await this.mailer.send({
|
|
58
|
+
to: 'user@example.com',
|
|
59
|
+
subject: 'Order Confirmation',
|
|
60
|
+
html: await this.mailer.render('order', { id: 123 }),
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## Security Recommendations
|
|
67
|
+
- ALWAYS rotate SMTP passwords
|
|
68
|
+
- Use app passwords where possible
|
|
69
|
+
- Disable insecure ports (25)
|
|
70
|
+
- Use encrypted SMTP (TLS)
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## Troubleshooting
|
|
75
|
+
|
|
76
|
+
| Error | Meaning | Fix |
|
|
77
|
+
|------|---------|-----|
|
|
78
|
+
| `ECONNREFUSED` | Cannot connect | wrong host/port |
|
|
79
|
+
| `EAUTH` | Auth failed | wrong credentials |
|
|
80
|
+
| `ETIMEDOUT` | Firewall blocks connection | allow outbound 587 |
|
|
81
|
+
|
package/index.d.ts
ADDED
package/index.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC"}
|
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lib/smtp-mail.provider.js';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ConfigService } from '@nestjs/config';
|
|
2
|
+
import * as nodemailer from 'nodemailer';
|
|
3
|
+
import { type MailerMessagesResolved, MailerProvider } from '@brilab-mailer/contracts';
|
|
4
|
+
import { Address, AttachmentLike } from "nodemailer/lib/mailer/index.js";
|
|
5
|
+
import { Readable } from "stream";
|
|
6
|
+
type MailOptionsType = {
|
|
7
|
+
from?: string | Address | undefined;
|
|
8
|
+
to?: string | Address | Array<string | Address> | undefined;
|
|
9
|
+
subject?: string | undefined;
|
|
10
|
+
text?: string | Buffer | Readable | AttachmentLike | undefined;
|
|
11
|
+
html?: string | Buffer | Readable | AttachmentLike | undefined;
|
|
12
|
+
};
|
|
13
|
+
export declare class SmtpMailProvider implements MailerProvider<any, any> {
|
|
14
|
+
private readonly config;
|
|
15
|
+
private _client;
|
|
16
|
+
constructor(config: ConfigService);
|
|
17
|
+
getClient(): nodemailer.Transporter;
|
|
18
|
+
createPayload(resolved: MailerMessagesResolved): MailOptionsType;
|
|
19
|
+
send(payload: MailOptionsType): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=smtp-mail.provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"smtp-mail.provider.d.ts","sourceRoot":"","sources":["../../src/lib/smtp-mail.provider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,UAAU,MAAM,YAAY,CAAC;AACzC,OAAO,EACL,KAAK,sBAAsB,EAC3B,cAAc,EACf,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC,KAAK,eAAe,GAAG;IACrB,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC;IACpC,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,KAAK,CAAC,MAAM,GAAG,OAAO,CAAC,GAAG,SAAS,CAAC;IAC5D,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,QAAQ,GAAG,cAAc,GAAG,SAAS,CAAC;IAC/D,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,QAAQ,GAAG,cAAc,GAAG,SAAS,CAAC;CAChE,CAAA;AAED,qBACa,gBAAiB,YAAW,cAAc,CAAC,GAAG,EAAC,GAAG,CAAC;IAGlD,OAAO,CAAC,QAAQ,CAAC,MAAM;IAFnC,OAAO,CAAC,OAAO,CAAyB;gBAEX,MAAM,EAAE,aAAa;IAY3C,SAAS,IAAI,UAAU,CAAC,WAAW;IAKnC,aAAa,CAAC,QAAQ,EAAE,sBAAsB,GAAG,eAAe;IAejE,IAAI,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;CAGpD"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { Injectable } from '@nestjs/common';
|
|
3
|
+
import { ConfigService } from '@nestjs/config';
|
|
4
|
+
import * as nodemailer from 'nodemailer';
|
|
5
|
+
import { segmentedDataContentPayload, } from '@brilab-mailer/contracts';
|
|
6
|
+
let SmtpMailProvider = class SmtpMailProvider {
|
|
7
|
+
config;
|
|
8
|
+
_client;
|
|
9
|
+
constructor(config) {
|
|
10
|
+
this.config = config;
|
|
11
|
+
this._client = nodemailer.createTransport({
|
|
12
|
+
host: this.config.get('MAIL_HOST'),
|
|
13
|
+
port: this.config.get('MAIL_PORT'),
|
|
14
|
+
auth: {
|
|
15
|
+
user: this.config.get('MAIL_USER'),
|
|
16
|
+
pass: this.config.get('MAIL_PASS'),
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
getClient() {
|
|
21
|
+
return this._client;
|
|
22
|
+
}
|
|
23
|
+
createPayload(resolved) {
|
|
24
|
+
const base = {
|
|
25
|
+
from: resolved.from.email,
|
|
26
|
+
to: resolved.to.map((t) => t.email).join(', '),
|
|
27
|
+
subject: resolved.subject,
|
|
28
|
+
};
|
|
29
|
+
return segmentedDataContentPayload(resolved, null, null, base);
|
|
30
|
+
}
|
|
31
|
+
async send(payload) {
|
|
32
|
+
await this._client.sendMail(payload);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
SmtpMailProvider = __decorate([
|
|
36
|
+
Injectable(),
|
|
37
|
+
__metadata("design:paramtypes", [ConfigService])
|
|
38
|
+
], SmtpMailProvider);
|
|
39
|
+
export { SmtpMailProvider };
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@brilab-mailer/provider-smtp",
|
|
3
|
+
"version": "0.0.1-beta.47",
|
|
4
|
+
"author": "Bohdan Radchenko <radchenkobs@gmail.com>",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./index.js",
|
|
7
|
+
"module": "./index.js",
|
|
8
|
+
"types": "./index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
"./package.json": "./package.json",
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./index.d.ts",
|
|
13
|
+
"import": "./index.js",
|
|
14
|
+
"default": "./index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"**/*",
|
|
19
|
+
"!**/*.tsbuildinfo"
|
|
20
|
+
],
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public",
|
|
24
|
+
"directory": "dist"
|
|
25
|
+
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"@nestjs/common": "^10.0.0",
|
|
28
|
+
"@nestjs/config": "^3.0.0",
|
|
29
|
+
"@brilab-mailer/contracts": "^0.0.1",
|
|
30
|
+
"@brilab-mailer/core": "^0.0.1"
|
|
31
|
+
},
|
|
32
|
+
"peerDependenciesMeta": {
|
|
33
|
+
"@brilab-mailer/contracts": {
|
|
34
|
+
"optional": false
|
|
35
|
+
},
|
|
36
|
+
"@brilab-mailer/core": {
|
|
37
|
+
"optional": true
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"typescript": "^5.0.0",
|
|
42
|
+
"@types/nodemailer": "^6.4.0"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"nodemailer": "6.9.4"
|
|
46
|
+
}
|
|
47
|
+
}
|