@travetto/email-nodemailer 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/LICENSE +21 -0
- package/README.md +56 -0
- package/index.ts +1 -0
- package/package.json +38 -0
- package/src/nodemailer.ts +39 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 ArcSine Technologies
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
<!-- This file was generated by @travetto/doc and should not be modified directly -->
|
|
2
|
+
<!-- Please modify https://github.com/travetto/travetto/tree/main/module/email-nodemailer/doc.ts and execute "npx trv doc" to rebuild -->
|
|
3
|
+
# Email
|
|
4
|
+
## Email transmission module.
|
|
5
|
+
|
|
6
|
+
**Install: @travetto/email-nodemailer**
|
|
7
|
+
```bash
|
|
8
|
+
npm install @travetto/email-nodemailer
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
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):
|
|
12
|
+
|
|
13
|
+
**Code: sendmail to send all messages via the sendmail operation**
|
|
14
|
+
```typescript
|
|
15
|
+
import { InjectableFactory } from '@travetto/di';
|
|
16
|
+
import { NodemailerTransport } from '@travetto/email';
|
|
17
|
+
|
|
18
|
+
class Config {
|
|
19
|
+
@InjectableFactory()
|
|
20
|
+
static getTransport() {
|
|
21
|
+
return new NodemailerTransport({ sendmail: true });
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
**Code: smtp to send all messages via the smtp operation**
|
|
27
|
+
```typescript
|
|
28
|
+
import { InjectableFactory } from '@travetto/di';
|
|
29
|
+
import { NodemailerTransport } from '@travetto/email';
|
|
30
|
+
|
|
31
|
+
class Config {
|
|
32
|
+
@InjectableFactory()
|
|
33
|
+
static getTransport() {
|
|
34
|
+
return new NodemailerTransport({
|
|
35
|
+
service: 'smtp'
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
**Code: ses to send all messages via the ses operation**
|
|
42
|
+
```typescript
|
|
43
|
+
import { SESClient } from '@aws-sdk/client-ses';
|
|
44
|
+
|
|
45
|
+
import { InjectableFactory } from '@travetto/di';
|
|
46
|
+
import { NodemailerTransport } from '@travetto/email';
|
|
47
|
+
|
|
48
|
+
class Config {
|
|
49
|
+
@InjectableFactory()
|
|
50
|
+
static getTransport() {
|
|
51
|
+
return new NodemailerTransport({
|
|
52
|
+
SES: SESClient
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
```
|
package/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './src/nodemailer';
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@travetto/email-nodemailer",
|
|
3
|
+
"displayName": "Email",
|
|
4
|
+
"version": "3.0.0-rc.0",
|
|
5
|
+
"description": "Email transmission module.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"email",
|
|
8
|
+
"nodemailer",
|
|
9
|
+
"travetto",
|
|
10
|
+
"typescript"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://travetto.io",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"author": {
|
|
15
|
+
"email": "travetto.framework@gmail.com",
|
|
16
|
+
"name": "Travetto Framework"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"index.ts",
|
|
20
|
+
"src"
|
|
21
|
+
],
|
|
22
|
+
"main": "index.ts",
|
|
23
|
+
"repository": {
|
|
24
|
+
"url": "https://github.com/travetto/travetto.git",
|
|
25
|
+
"directory": "module/email-nodemailer"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@travetto/email": "^3.0.0-rc.0",
|
|
29
|
+
"@types/nodemailer": "^6.4.5",
|
|
30
|
+
"nodemailer": "^6.7.8"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
35
|
+
"docDependencies": {
|
|
36
|
+
"@aws-sdk/client-ses": "^3.160.0"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * 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';
|
|
6
|
+
|
|
7
|
+
import { MailTransport, MessageOptions, SentMessage } from '@travetto/email';
|
|
8
|
+
|
|
9
|
+
type Transport = nodemailer.Transport | json.Options | smtp.Options | ses.Options | sendmail.Options;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Nodemailer transport, takes in a transport factory as the input
|
|
13
|
+
*/
|
|
14
|
+
export class NodemailerTransport implements MailTransport {
|
|
15
|
+
#transport: nodemailer.Transporter;
|
|
16
|
+
|
|
17
|
+
constructor(transportFactory: Transport) {
|
|
18
|
+
this.#transport = nodemailer.createTransport(transportFactory);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async send<S extends SentMessage = SentMessage>(mail: MessageOptions): Promise<S> {
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
23
|
+
const res = await this.#transport.sendMail(mail) as {
|
|
24
|
+
messageId?: string;
|
|
25
|
+
envelope?: Record<string, string>;
|
|
26
|
+
accepted?: string[];
|
|
27
|
+
rejected?: string[];
|
|
28
|
+
pending?: string[];
|
|
29
|
+
response?: string;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
if (res.rejected?.length) {
|
|
33
|
+
console.error('Unable to send emails', { recipientCount: res.rejected?.length });
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
37
|
+
return res as S;
|
|
38
|
+
}
|
|
39
|
+
}
|