@brilab-mailer/provider-smtp 0.0.5-5 → 0.1.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.
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type OnModuleInit } from '@nestjs/common';
|
|
2
|
+
import { type MailerMessagesResolved, MailerProvider, type MailerSendResult } from '@brilab-mailer/contracts';
|
|
2
3
|
import { Transporter } from "nodemailer";
|
|
3
4
|
import * as SMTPTransport from "nodemailer/lib/smtp-transport/index.js";
|
|
4
5
|
import * as SMTPConnection from "nodemailer/lib/smtp-connection/index.js";
|
|
@@ -6,13 +7,16 @@ import * as NodemailerMailer from "nodemailer/lib/mailer/index.js";
|
|
|
6
7
|
type Config = SMTPConnection.Options;
|
|
7
8
|
type Client = Transporter<SMTPTransport.SentMessageInfo, SMTPTransport.Options>;
|
|
8
9
|
type Mail = NodemailerMailer.Options;
|
|
9
|
-
export declare class MailerSmtpProvider implements MailerProvider<Config, Client, Mail
|
|
10
|
+
export declare class MailerSmtpProvider implements MailerProvider<Config, Client, Mail>, OnModuleInit {
|
|
10
11
|
private readonly options;
|
|
12
|
+
private readonly logger;
|
|
11
13
|
private readonly _client;
|
|
12
14
|
constructor(options: Config);
|
|
15
|
+
/** Fast-fail check of SMTP connectivity/auth at startup (non-blocking). */
|
|
16
|
+
onModuleInit(): Promise<void>;
|
|
13
17
|
getClient(): Client;
|
|
14
18
|
createPayload(resolved: MailerMessagesResolved): Mail;
|
|
15
|
-
send(payload: Mail): Promise<
|
|
19
|
+
send(payload: Mail): Promise<MailerSendResult>;
|
|
16
20
|
}
|
|
17
21
|
export {};
|
|
18
22
|
//# sourceMappingURL=mailer-smtp.provider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mailer-smtp.provider.d.ts","sourceRoot":"","sources":["../../src/lib/mailer-smtp.provider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mailer-smtp.provider.d.ts","sourceRoot":"","sources":["../../src/lib/mailer-smtp.provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC/E,OAAO,EAGN,KAAK,sBAAsB,EAC3B,cAAc,EACd,KAAK,gBAAgB,EAGrB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAmB,WAAW,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,KAAK,aAAa,MAAM,wCAAwC,CAAC;AACxE,OAAO,KAAK,cAAc,MAAM,yCAAyC,CAAC;AAC1E,OAAO,KAAK,gBAAgB,MAAM,gCAAgC,CAAC;AAGnE,KAAK,MAAM,GAAG,cAAc,CAAC,OAAO,CAAC;AACrC,KAAK,MAAM,GAAG,WAAW,CAAC,aAAa,CAAC,eAAe,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;AAChF,KAAK,IAAI,GAAG,gBAAgB,CAAC,OAAO,CAAC;AAMrC,qBACa,kBAAmB,YAAW,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,YAAY;IAM3F,OAAO,CAAC,QAAQ,CAAC,OAAO;IALzB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuC;IAC9D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAIf,OAAO,EAAE,MAAM;IAKjC,2EAA2E;IACrE,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAS5B,SAAS,IAAI,MAAM;IAInB,aAAa,CAAC,QAAQ,EAAE,sBAAsB,GAAG,IAAI;IAuBtD,IAAI,CAAC,OAAO,EAAE,IAAI,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAapD"}
|
|
@@ -1,32 +1,69 @@
|
|
|
1
|
+
var MailerSmtpProvider_1;
|
|
1
2
|
import { __decorate, __metadata, __param } from "tslib";
|
|
2
|
-
import { Inject, Injectable } from '@nestjs/common';
|
|
3
|
-
import { MAILER_PROVIDER_OPTIONS,
|
|
3
|
+
import { Inject, Injectable, Logger } from '@nestjs/common';
|
|
4
|
+
import { MAILER_PROVIDER_OPTIONS, toMailerSendError, resolveBodies, } from '@brilab-mailer/contracts';
|
|
4
5
|
import { createTransport } from "nodemailer";
|
|
5
|
-
|
|
6
|
+
const toAddress = (a) => ({ name: a.name ?? '', address: a.email });
|
|
7
|
+
const addressToString = (a) => (typeof a === 'string' ? a : a.address);
|
|
8
|
+
let MailerSmtpProvider = MailerSmtpProvider_1 = class MailerSmtpProvider {
|
|
6
9
|
options;
|
|
10
|
+
logger = new Logger(MailerSmtpProvider_1.name);
|
|
7
11
|
_client;
|
|
8
12
|
constructor(options) {
|
|
9
13
|
this.options = options;
|
|
10
|
-
this._client = createTransport({
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
this._client = createTransport({ ...this.options });
|
|
15
|
+
}
|
|
16
|
+
/** Fast-fail check of SMTP connectivity/auth at startup (non-blocking). */
|
|
17
|
+
async onModuleInit() {
|
|
18
|
+
try {
|
|
19
|
+
await this._client.verify();
|
|
20
|
+
this.logger.log('SMTP transport verified');
|
|
21
|
+
}
|
|
22
|
+
catch (err) {
|
|
23
|
+
this.logger.warn(`SMTP transport verification failed: ${err?.message}`);
|
|
24
|
+
}
|
|
13
25
|
}
|
|
14
26
|
getClient() {
|
|
15
27
|
return this._client;
|
|
16
28
|
}
|
|
17
29
|
createPayload(resolved) {
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
30
|
+
const { text, html } = resolveBodies(resolved);
|
|
31
|
+
return {
|
|
32
|
+
from: toAddress(resolved.from),
|
|
33
|
+
to: resolved.to.map(toAddress),
|
|
34
|
+
cc: resolved.cc?.map(toAddress),
|
|
35
|
+
bcc: resolved.bcc?.map(toAddress),
|
|
36
|
+
replyTo: resolved.replyTo ? toAddress(resolved.replyTo) : undefined,
|
|
21
37
|
subject: resolved.subject,
|
|
38
|
+
headers: resolved.headers,
|
|
39
|
+
text,
|
|
40
|
+
html,
|
|
41
|
+
attachments: resolved.attachments?.map((att) => ({
|
|
42
|
+
filename: att.filename,
|
|
43
|
+
content: att.content,
|
|
44
|
+
path: att.path,
|
|
45
|
+
contentType: att.contentType,
|
|
46
|
+
cid: att.contentId,
|
|
47
|
+
contentDisposition: att.disposition,
|
|
48
|
+
})),
|
|
22
49
|
};
|
|
23
|
-
return segmentedDataContentPayload(resolved, null, null, base);
|
|
24
50
|
}
|
|
25
51
|
async send(payload) {
|
|
26
|
-
|
|
52
|
+
try {
|
|
53
|
+
const info = await this._client.sendMail(payload);
|
|
54
|
+
return {
|
|
55
|
+
messageId: info.messageId,
|
|
56
|
+
accepted: info.accepted?.map(addressToString),
|
|
57
|
+
rejected: info.rejected?.map(addressToString),
|
|
58
|
+
raw: info,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
catch (err) {
|
|
62
|
+
throw toMailerSendError('MailerSmtpProvider', err);
|
|
63
|
+
}
|
|
27
64
|
}
|
|
28
65
|
};
|
|
29
|
-
MailerSmtpProvider = __decorate([
|
|
66
|
+
MailerSmtpProvider = MailerSmtpProvider_1 = __decorate([
|
|
30
67
|
Injectable(),
|
|
31
68
|
__param(0, Inject(MAILER_PROVIDER_OPTIONS)),
|
|
32
69
|
__metadata("design:paramtypes", [Object])
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brilab-mailer/provider-smtp",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"author": "Bohdan Radchenko <radchenkobs@gmail.com>",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.js",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"@nestjs/common": "^10.0.0",
|
|
28
28
|
"@nestjs/config": "^3.0.0",
|
|
29
|
-
"@brilab-mailer/contracts": "^0.0
|
|
30
|
-
"@brilab-mailer/core": "^0.0
|
|
29
|
+
"@brilab-mailer/contracts": "^0.1.0",
|
|
30
|
+
"@brilab-mailer/core": "^0.1.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependenciesMeta": {
|
|
33
33
|
"@brilab-mailer/contracts": {
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"typescript": "^5.0.0",
|
|
42
|
-
"@types/nodemailer": "^6.4.
|
|
42
|
+
"@types/nodemailer": "^6.4.21"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"nodemailer": "
|
|
45
|
+
"nodemailer": "^8.0.10"
|
|
46
46
|
}
|
|
47
47
|
}
|