@travetto/email 2.2.7 → 3.0.0-rc.0
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 +0 -49
- package/index.ts +1 -3
- package/package.json +3 -10
- package/src/extension/nodemailer.ts +14 -7
package/README.md
CHANGED
|
@@ -34,52 +34,3 @@ By design, sending an email requires the sender to specify the html, text option
|
|
|
34
34
|
* `resources/<key>.compiled.text`
|
|
35
35
|
* `resources/<key>.compiled.subject`
|
|
36
36
|
With `.html` being the only required field. The [Email Templating](https://github.com/travetto/travetto/tree/main/module/email-template#readme "Email templating module") module supports this format, and will generate files accordingly. Also, note that `<key>` can include slashes, allowing for nesting folders.
|
|
37
|
-
|
|
38
|
-
## Nodemailer - Extension
|
|
39
|
-
|
|
40
|
-
Given the integration with [nodemailer](https://nodemailer.com/about/), all extensions should be usable out of the box. The primary [nodemailer](https://nodemailer.com/about/) modules are provided (assuming dependencies are installed):
|
|
41
|
-
|
|
42
|
-
**Code: sendmail to send all messages via the sendmail operation**
|
|
43
|
-
```typescript
|
|
44
|
-
import { InjectableFactory } from '@travetto/di';
|
|
45
|
-
import { NodemailerTransport } from '@travetto/email';
|
|
46
|
-
|
|
47
|
-
class Config {
|
|
48
|
-
@InjectableFactory()
|
|
49
|
-
static getTransport() {
|
|
50
|
-
return new NodemailerTransport({ sendmail: true });
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
**Code: smtp to send all messages via the smtp operation**
|
|
56
|
-
```typescript
|
|
57
|
-
import { InjectableFactory } from '@travetto/di';
|
|
58
|
-
import { NodemailerTransport } from '@travetto/email';
|
|
59
|
-
|
|
60
|
-
class Config {
|
|
61
|
-
@InjectableFactory()
|
|
62
|
-
static getTransport() {
|
|
63
|
-
return new NodemailerTransport({
|
|
64
|
-
service: 'smtp'
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
**Code: ses to send all messages via the ses operation**
|
|
71
|
-
```typescript
|
|
72
|
-
import { SESClient } from '@aws-sdk/client-ses';
|
|
73
|
-
|
|
74
|
-
import { InjectableFactory } from '@travetto/di';
|
|
75
|
-
import { NodemailerTransport } from '@travetto/email';
|
|
76
|
-
|
|
77
|
-
class Config {
|
|
78
|
-
@InjectableFactory()
|
|
79
|
-
static getTransport() {
|
|
80
|
-
return new NodemailerTransport({
|
|
81
|
-
SES: SESClient
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
```
|
package/index.ts
CHANGED
|
@@ -3,6 +3,4 @@ export * from './src/types';
|
|
|
3
3
|
export * from './src/config';
|
|
4
4
|
export * from './src/transport';
|
|
5
5
|
export * from './src/util';
|
|
6
|
-
export * from './src/template';
|
|
7
|
-
// Named export needed for proxying
|
|
8
|
-
export { NodemailerTransport } from './src/extension/nodemailer';
|
|
6
|
+
export * from './src/template';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/email",
|
|
3
3
|
"displayName": "Email",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "3.0.0-rc.0",
|
|
5
5
|
"description": "Email transmission module.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"email",
|
|
@@ -24,19 +24,12 @@
|
|
|
24
24
|
"directory": "module/email"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@travetto/config": "^
|
|
28
|
-
"@travetto/di": "^
|
|
27
|
+
"@travetto/config": "^3.0.0-rc.0",
|
|
28
|
+
"@travetto/di": "^3.0.0-rc.0",
|
|
29
29
|
"@types/mustache": "^4.2.1",
|
|
30
30
|
"mustache": "^4.2.0"
|
|
31
31
|
},
|
|
32
|
-
"optionalPeerDependencies": {
|
|
33
|
-
"nodemailer": "^6.7.8",
|
|
34
|
-
"@types/nodemailer": "^6.4.5"
|
|
35
|
-
},
|
|
36
32
|
"publishConfig": {
|
|
37
33
|
"access": "public"
|
|
38
|
-
},
|
|
39
|
-
"docDependencies": {
|
|
40
|
-
"@aws-sdk/client-ses": "^3.154.0"
|
|
41
34
|
}
|
|
42
35
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
import * as
|
|
3
|
-
import * as
|
|
4
|
-
import * as
|
|
5
|
-
import * as
|
|
6
|
-
import * as sendmail from 'nodemailer/lib/sendmail-transport';
|
|
1
|
+
import type * as nodemailer from 'nodemailer';
|
|
2
|
+
import type * as json from 'nodemailer/lib/json-transport';
|
|
3
|
+
import type * as smtp from 'nodemailer/lib/smtp-transport';
|
|
4
|
+
import type * as ses from 'nodemailer/lib/ses-transport';
|
|
5
|
+
import type * as sendmail from 'nodemailer/lib/sendmail-transport';
|
|
7
6
|
|
|
8
7
|
import { MessageOptions, SentMessage } from '../types';
|
|
9
8
|
import { MailTransport } from '../transport';
|
|
@@ -17,7 +16,15 @@ export class NodemailerTransport implements MailTransport {
|
|
|
17
16
|
#transport: nodemailer.Transporter;
|
|
18
17
|
|
|
19
18
|
constructor(transportFactory: Transport) {
|
|
20
|
-
|
|
19
|
+
try {
|
|
20
|
+
const nm = require('nodemailer');
|
|
21
|
+
this.#transport = nm.createTransport(transportFactory);
|
|
22
|
+
} catch (err) {
|
|
23
|
+
if (err instanceof Error) {
|
|
24
|
+
console.error('Please install nodemailer before use: "npm install nodemailer"');
|
|
25
|
+
}
|
|
26
|
+
throw err;
|
|
27
|
+
}
|
|
21
28
|
}
|
|
22
29
|
|
|
23
30
|
async send<S extends SentMessage = SentMessage>(mail: MessageOptions): Promise<S> {
|