@tc-libs/email-sender 3.6.0 → 3.6.1
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 +80 -6
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -1,11 +1,85 @@
|
|
|
1
|
-
# email-sender
|
|
1
|
+
# @tc-libs/email-sender
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Servizio email basato su Mailgun con supporto a template EJS e persistenza template su database.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Il package esporta:
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- `EmailSenderModule`
|
|
8
|
+
- `EmailSenderService`
|
|
9
|
+
- DTO `SendTemplateDto`
|
|
10
|
+
- entity `EmailEntity`
|
|
8
11
|
|
|
9
|
-
##
|
|
12
|
+
## Registrazione
|
|
10
13
|
|
|
11
|
-
|
|
14
|
+
```ts
|
|
15
|
+
EmailSenderModule.register(
|
|
16
|
+
{
|
|
17
|
+
email: {
|
|
18
|
+
enabled: true,
|
|
19
|
+
from: 'noreply@example.com',
|
|
20
|
+
cc: [],
|
|
21
|
+
bcc: [],
|
|
22
|
+
mailgun: {
|
|
23
|
+
host: 'api.mailgun.net',
|
|
24
|
+
key: process.env.MAILGUN_KEY!,
|
|
25
|
+
domain: process.env.MAILGUN_DOMAIN!,
|
|
26
|
+
},
|
|
27
|
+
templateDir: './templates/email',
|
|
28
|
+
},
|
|
29
|
+
app: {
|
|
30
|
+
endpoints: {
|
|
31
|
+
frontend: 'https://app.example.com',
|
|
32
|
+
backoffice: 'https://admin.example.com',
|
|
33
|
+
backend: 'https://api.example.com',
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
aws: {
|
|
37
|
+
s3: {
|
|
38
|
+
baseUrl: 'https://cdn.example.com',
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
true,
|
|
43
|
+
);
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Operazioni principali
|
|
47
|
+
|
|
48
|
+
- `sendTemplate({ lang, template, options, variables })`
|
|
49
|
+
- `sendText(text, subject, options)`
|
|
50
|
+
- `createAttachment(...)`
|
|
51
|
+
- gestione mailing list Mailgun
|
|
52
|
+
|
|
53
|
+
Esempio template:
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
await this.emailSenderService.sendTemplate({
|
|
57
|
+
lang: 'it',
|
|
58
|
+
template: 'welcome',
|
|
59
|
+
variables: {
|
|
60
|
+
name: 'Mario',
|
|
61
|
+
},
|
|
62
|
+
options: {
|
|
63
|
+
to: ['mario@example.com'],
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Come funziona `sendTemplate`
|
|
69
|
+
|
|
70
|
+
- carica l'HTML da file locale o URL remoto
|
|
71
|
+
- compila il template EJS
|
|
72
|
+
- legge da database il template email per subject, labels e destinatari default
|
|
73
|
+
- inietta variabili condivise come `frontend`, `backoffice`, `backend`, `cdn`
|
|
74
|
+
- invia tramite Mailgun
|
|
75
|
+
|
|
76
|
+
## Nota importante
|
|
77
|
+
|
|
78
|
+
Il package assume l'esistenza di template email persistiti nella collection dedicata, non solo file `.html` locali.
|
|
79
|
+
|
|
80
|
+
## Sviluppo
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
nx build email-sender
|
|
84
|
+
nx test email-sender
|
|
85
|
+
```
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tc-libs/email-sender",
|
|
3
|
-
"version": "3.6.
|
|
3
|
+
"version": "3.6.1",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@tc-libs/database": "3.6.
|
|
6
|
-
"@tc-libs/app-cache": "3.6.
|
|
7
|
-
"@tc-libs/service": "3.6.
|
|
8
|
-
"@tc-libs/pagination": "3.6.
|
|
9
|
-
"@tc-libs/errors": "3.6.
|
|
5
|
+
"@tc-libs/database": "3.6.1",
|
|
6
|
+
"@tc-libs/app-cache": "3.6.1",
|
|
7
|
+
"@tc-libs/service": "3.6.1",
|
|
8
|
+
"@tc-libs/pagination": "3.6.1",
|
|
9
|
+
"@tc-libs/errors": "3.6.1",
|
|
10
10
|
"class-validator": "^0.14.1",
|
|
11
11
|
"@nestjs/common": "^11.0.12",
|
|
12
12
|
"@nestjs/mongoose": "^11.0.3",
|