@travetto/email-nodemailer 8.0.0-alpha.9 → 8.0.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 +17 -4
- package/__index__.ts +1 -1
- package/package.json +14 -14
- package/src/nodemailer.ts +16 -12
package/README.md
CHANGED
|
@@ -30,14 +30,27 @@ class Config {
|
|
|
30
30
|
|
|
31
31
|
**Code: smtp to send all messages via the smtp operation**
|
|
32
32
|
```typescript
|
|
33
|
+
import { Config } from '@travetto/config';
|
|
33
34
|
import { InjectableFactory } from '@travetto/di';
|
|
34
35
|
import { NodemailerTransport } from '@travetto/email-nodemailer';
|
|
35
36
|
|
|
36
|
-
|
|
37
|
+
@Config('email.nodemailer')
|
|
38
|
+
export class NodemailerSmtpConfig {
|
|
39
|
+
host: string = 'smtp.send-grid.net';
|
|
40
|
+
port: number = 587;
|
|
41
|
+
secure: boolean = false;
|
|
42
|
+
username?: string = 'api-key';
|
|
43
|
+
password?: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export class NodemailerTransportFactory {
|
|
37
47
|
@InjectableFactory()
|
|
38
|
-
static
|
|
48
|
+
static createSmtpTransport(config: NodemailerSmtpConfig): NodemailerTransport {
|
|
39
49
|
return new NodemailerTransport({
|
|
40
|
-
|
|
50
|
+
host: config.host,
|
|
51
|
+
port: config.port,
|
|
52
|
+
secure: config.secure,
|
|
53
|
+
auth: config.password ? { user: config.username, pass: config.password } : undefined
|
|
41
54
|
});
|
|
42
55
|
}
|
|
43
56
|
}
|
|
@@ -57,7 +70,7 @@ class Config {
|
|
|
57
70
|
SES: {
|
|
58
71
|
sesClient: new SESv2Client(),
|
|
59
72
|
SendEmailCommand
|
|
60
|
-
}
|
|
73
|
+
}
|
|
61
74
|
});
|
|
62
75
|
}
|
|
63
76
|
}
|
package/__index__.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './src/nodemailer.ts';
|
|
1
|
+
export * from './src/nodemailer.ts';
|
package/package.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/email-nodemailer",
|
|
3
|
-
"version": "8.0.
|
|
4
|
-
"type": "module",
|
|
3
|
+
"version": "8.0.1",
|
|
5
4
|
"description": "Email transmission module.",
|
|
6
5
|
"keywords": [
|
|
7
6
|
"email",
|
|
@@ -12,30 +11,31 @@
|
|
|
12
11
|
"homepage": "https://travetto.io",
|
|
13
12
|
"license": "MIT",
|
|
14
13
|
"author": {
|
|
15
|
-
"
|
|
16
|
-
"
|
|
14
|
+
"name": "Travetto Framework",
|
|
15
|
+
"email": "travetto.framework@gmail.com"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"url": "git+https://github.com/travetto/travetto.git",
|
|
19
|
+
"directory": "module/email-nodemailer"
|
|
17
20
|
},
|
|
18
21
|
"files": [
|
|
19
22
|
"__index__.ts",
|
|
20
23
|
"src"
|
|
21
24
|
],
|
|
25
|
+
"type": "module",
|
|
22
26
|
"main": "__index__.ts",
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"directory": "module/email-nodemailer"
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
26
29
|
},
|
|
27
30
|
"dependencies": {
|
|
28
|
-
"@travetto/email": "^8.0.
|
|
29
|
-
"@types/nodemailer": "^
|
|
30
|
-
"nodemailer": "^
|
|
31
|
+
"@travetto/email": "^8.0.1",
|
|
32
|
+
"@types/nodemailer": "^8.0.1",
|
|
33
|
+
"nodemailer": "^9.1.1"
|
|
31
34
|
},
|
|
32
35
|
"devDependencies": {
|
|
33
|
-
"@aws-sdk/client-sesv2": "^3.
|
|
36
|
+
"@aws-sdk/client-sesv2": "^3.1127.0"
|
|
34
37
|
},
|
|
35
38
|
"travetto": {
|
|
36
39
|
"displayName": "Email Nodemailer Support"
|
|
37
|
-
},
|
|
38
|
-
"publishConfig": {
|
|
39
|
-
"access": "public"
|
|
40
40
|
}
|
|
41
41
|
}
|
package/src/nodemailer.ts
CHANGED
|
@@ -2,12 +2,12 @@ import type { Readable } from 'node:stream';
|
|
|
2
2
|
|
|
3
3
|
import { createTransport, type Transporter, type Transport as TransportType } from 'nodemailer';
|
|
4
4
|
import type json from 'nodemailer/lib/json-transport';
|
|
5
|
-
import type smtp from 'nodemailer/lib/smtp-transport';
|
|
6
|
-
import type ses from 'nodemailer/lib/ses-transport';
|
|
7
5
|
import type sendmail from 'nodemailer/lib/sendmail-transport';
|
|
6
|
+
import type ses from 'nodemailer/lib/ses-transport';
|
|
7
|
+
import type smtp from 'nodemailer/lib/smtp-transport';
|
|
8
8
|
|
|
9
|
-
import
|
|
10
|
-
import { BinaryUtil,
|
|
9
|
+
import type { EmailOptions, MailTransport, SentEmail } from '@travetto/email';
|
|
10
|
+
import { BinaryUtil, CodecUtil, castTo } from '@travetto/runtime';
|
|
11
11
|
|
|
12
12
|
type Transport = TransportType | json.Options | smtp.Options | ses.Options | sendmail.Options;
|
|
13
13
|
|
|
@@ -15,13 +15,15 @@ type Transport = TransportType | json.Options | smtp.Options | ses.Options | sen
|
|
|
15
15
|
* Nodemailer transport, takes in a transport factory as the input
|
|
16
16
|
*/
|
|
17
17
|
export class NodemailerTransport implements MailTransport {
|
|
18
|
-
#transport: Transporter<
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
#transport: Transporter<
|
|
19
|
+
SentEmail & {
|
|
20
|
+
rejected?: unknown[];
|
|
21
|
+
}
|
|
22
|
+
>;
|
|
21
23
|
|
|
22
24
|
/**
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
* Enforce attachment content is a buffer or stream, converting from string or binary array if needed
|
|
26
|
+
*/
|
|
25
27
|
#enforceAttachmentContent(message: EmailOptions): EmailOptions<Readable | Buffer> {
|
|
26
28
|
for (const attachment of message.attachments ?? []) {
|
|
27
29
|
if (attachment.content) {
|
|
@@ -41,7 +43,10 @@ export class NodemailerTransport implements MailTransport {
|
|
|
41
43
|
* Force content into alternative slots
|
|
42
44
|
*/
|
|
43
45
|
#forceContentToAlternative(message: EmailOptions): EmailOptions {
|
|
44
|
-
for (const [key, mime] of [
|
|
46
|
+
for (const [key, mime] of [
|
|
47
|
+
['text', 'text/plain'],
|
|
48
|
+
['html', 'text/html']
|
|
49
|
+
] as const) {
|
|
45
50
|
if (message[key]) {
|
|
46
51
|
(message.alternatives ??= []).push({
|
|
47
52
|
content: message[key],
|
|
@@ -61,7 +66,6 @@ export class NodemailerTransport implements MailTransport {
|
|
|
61
66
|
}
|
|
62
67
|
|
|
63
68
|
async send<S extends SentEmail = SentEmail>(mail: EmailOptions): Promise<S> {
|
|
64
|
-
|
|
65
69
|
const forced = this.#enforceAttachmentContent(this.#forceContentToAlternative(mail));
|
|
66
70
|
|
|
67
71
|
const response = await this.#transport.sendMail(forced);
|
|
@@ -72,4 +76,4 @@ export class NodemailerTransport implements MailTransport {
|
|
|
72
76
|
|
|
73
77
|
return castTo(response);
|
|
74
78
|
}
|
|
75
|
-
}
|
|
79
|
+
}
|