@tomei/mailer 0.6.2 → 0.7.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/.gitlab-ci.yml +16 -16
- package/.husky/commit-msg +15 -15
- package/.husky/pre-commit +8 -8
- package/dist/src/mailer/smtp-mailer.js +13 -0
- package/dist/src/mailer/smtp-mailer.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/eslint.config.mjs +58 -58
- package/package.json +47 -47
- package/sonar-project.properties +12 -12
- package/src/enum/email-status.enum.ts +4 -4
- package/src/enum/index.ts +1 -1
- package/src/interfaces/log-transaction-options.interface.ts +18 -18
- package/src/interfaces/mail-config.interface.ts +8 -8
- package/src/interfaces/mail-log.interface.ts +12 -12
- package/src/mailer/index.ts +2 -2
- package/src/mailer/mailer.base.ts +110 -110
- package/src/mailer/smtp-mailer.ts +121 -94
|
@@ -1,94 +1,121 @@
|
|
|
1
|
-
import { ComponentConfig } from '@tomei/config';
|
|
2
|
-
import { MailerBase } from './mailer.base';
|
|
3
|
-
import * as nodemailer from 'nodemailer';
|
|
4
|
-
import { ISendMailConfig } from 'src/interfaces/mail-config.interface';
|
|
5
|
-
|
|
6
|
-
interface TransportConfig {
|
|
7
|
-
host: string;
|
|
8
|
-
port: number;
|
|
9
|
-
secure: boolean;
|
|
10
|
-
auth: {
|
|
11
|
-
user: string;
|
|
12
|
-
pass: string;
|
|
13
|
-
};
|
|
14
|
-
tls?: any;
|
|
15
|
-
debug?: boolean;
|
|
16
|
-
logger?: boolean;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export class SMTPMailer extends MailerBase {
|
|
20
|
-
async sendMail(options: ISendMailConfig): Promise<void> {
|
|
21
|
-
try {
|
|
22
|
-
const host = ComponentConfig.getComponentConfigValue(
|
|
23
|
-
'@tomei/mailer',
|
|
24
|
-
'host',
|
|
25
|
-
);
|
|
26
|
-
const port = ComponentConfig.getComponentConfigValue(
|
|
27
|
-
'@tomei/mailer',
|
|
28
|
-
'port',
|
|
29
|
-
);
|
|
30
|
-
const secure = ComponentConfig.getComponentConfigValue(
|
|
31
|
-
'@tomei/mailer',
|
|
32
|
-
'secure',
|
|
33
|
-
);
|
|
34
|
-
const user = ComponentConfig.getComponentConfigValue(
|
|
35
|
-
'@tomei/mailer',
|
|
36
|
-
'user',
|
|
37
|
-
);
|
|
38
|
-
const pass = ComponentConfig.getComponentConfigValue(
|
|
39
|
-
'@tomei/mailer',
|
|
40
|
-
'pass',
|
|
41
|
-
);
|
|
42
|
-
const tlsOptions = ComponentConfig.getComponentConfigValue(
|
|
43
|
-
'@tomei/mailer',
|
|
44
|
-
'tlsOptions',
|
|
45
|
-
);
|
|
46
|
-
const isMailerDebugEnabled = ComponentConfig.getComponentConfigValue(
|
|
47
|
-
'@tomei/mailer',
|
|
48
|
-
'isMailerDebugEnabled',
|
|
49
|
-
);
|
|
50
|
-
const isMailerLogEnabled = ComponentConfig.getComponentConfigValue(
|
|
51
|
-
'@tomei/mailer',
|
|
52
|
-
'isMailerLogEnabled',
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
1
|
+
import { ComponentConfig } from '@tomei/config';
|
|
2
|
+
import { MailerBase } from './mailer.base';
|
|
3
|
+
import * as nodemailer from 'nodemailer';
|
|
4
|
+
import { ISendMailConfig } from 'src/interfaces/mail-config.interface';
|
|
5
|
+
|
|
6
|
+
interface TransportConfig {
|
|
7
|
+
host: string;
|
|
8
|
+
port: number;
|
|
9
|
+
secure: boolean;
|
|
10
|
+
auth: {
|
|
11
|
+
user: string;
|
|
12
|
+
pass: string;
|
|
13
|
+
};
|
|
14
|
+
tls?: any;
|
|
15
|
+
debug?: boolean;
|
|
16
|
+
logger?: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export class SMTPMailer extends MailerBase {
|
|
20
|
+
async sendMail(options: ISendMailConfig): Promise<void> {
|
|
21
|
+
try {
|
|
22
|
+
const host = ComponentConfig.getComponentConfigValue(
|
|
23
|
+
'@tomei/mailer',
|
|
24
|
+
'host',
|
|
25
|
+
);
|
|
26
|
+
const port = ComponentConfig.getComponentConfigValue(
|
|
27
|
+
'@tomei/mailer',
|
|
28
|
+
'port',
|
|
29
|
+
);
|
|
30
|
+
const secure = ComponentConfig.getComponentConfigValue(
|
|
31
|
+
'@tomei/mailer',
|
|
32
|
+
'secure',
|
|
33
|
+
);
|
|
34
|
+
const user = ComponentConfig.getComponentConfigValue(
|
|
35
|
+
'@tomei/mailer',
|
|
36
|
+
'user',
|
|
37
|
+
);
|
|
38
|
+
const pass = ComponentConfig.getComponentConfigValue(
|
|
39
|
+
'@tomei/mailer',
|
|
40
|
+
'pass',
|
|
41
|
+
);
|
|
42
|
+
const tlsOptions = ComponentConfig.getComponentConfigValue(
|
|
43
|
+
'@tomei/mailer',
|
|
44
|
+
'tlsOptions',
|
|
45
|
+
);
|
|
46
|
+
const isMailerDebugEnabled = ComponentConfig.getComponentConfigValue(
|
|
47
|
+
'@tomei/mailer',
|
|
48
|
+
'isMailerDebugEnabled',
|
|
49
|
+
);
|
|
50
|
+
const isMailerLogEnabled = ComponentConfig.getComponentConfigValue(
|
|
51
|
+
'@tomei/mailer',
|
|
52
|
+
'isMailerLogEnabled',
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const testReceipientEmail = ComponentConfig.getComponentConfigValue(
|
|
56
|
+
'@tomei/mailer',
|
|
57
|
+
'testReceipientEmail',
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
const environment = ComponentConfig.getComponentConfigValue(
|
|
61
|
+
'@tomei/mailer',
|
|
62
|
+
'environment',
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
if (
|
|
66
|
+
!host ||
|
|
67
|
+
!port ||
|
|
68
|
+
!user ||
|
|
69
|
+
!pass ||
|
|
70
|
+
!environment ||
|
|
71
|
+
!testReceipientEmail
|
|
72
|
+
) {
|
|
73
|
+
throw new Error(
|
|
74
|
+
'Host, port, user, pass, environment, or test receipient email is not defined in the configuration.',
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (environment !== 'production') {
|
|
79
|
+
options.to = testReceipientEmail;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const transportConfig: TransportConfig = {
|
|
83
|
+
host,
|
|
84
|
+
port,
|
|
85
|
+
secure,
|
|
86
|
+
auth: {
|
|
87
|
+
user,
|
|
88
|
+
pass,
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
if (tlsOptions) {
|
|
93
|
+
transportConfig.tls = tlsOptions;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (isMailerDebugEnabled) {
|
|
97
|
+
transportConfig.debug = true;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (isMailerLogEnabled) {
|
|
101
|
+
transportConfig.logger = true;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const transporter = nodemailer.createTransport(transportConfig);
|
|
105
|
+
|
|
106
|
+
await transporter.sendMail({
|
|
107
|
+
from: options.from,
|
|
108
|
+
to: options.to,
|
|
109
|
+
subject: options.subject,
|
|
110
|
+
html: options.html,
|
|
111
|
+
cc: options.cc,
|
|
112
|
+
attachments: options.attachments,
|
|
113
|
+
});
|
|
114
|
+
} catch (error) {
|
|
115
|
+
console.log(error, '<<<<<<<<<< error caught from @tomei/mailer package');
|
|
116
|
+
throw error;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export { nodemailer };
|