@pixelplex/mail-service 0.1.21-attachments → 0.1.21-mailfile
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,20 +1,22 @@
|
|
|
1
1
|
import { OnApplicationBootstrap } from '@nestjs/common';
|
|
2
2
|
import { ClientProxy } from '@nestjs/microservices';
|
|
3
3
|
import { Observable } from 'rxjs';
|
|
4
|
+
import { Attachment } from 'nodemailer/lib/mailer';
|
|
4
5
|
export declare class MailService implements OnApplicationBootstrap {
|
|
5
6
|
private logger;
|
|
6
7
|
client: ClientProxy;
|
|
7
8
|
clientRecovery: ClientProxy;
|
|
8
9
|
onApplicationBootstrap(): Promise<void>;
|
|
9
10
|
/**
|
|
10
|
-
* @param to
|
|
11
|
-
* @param type
|
|
12
|
-
* @param payload
|
|
13
|
-
* @param
|
|
14
|
-
*
|
|
15
|
-
*
|
|
11
|
+
* @param to - email to send the message to
|
|
12
|
+
* @param type - the type of message to send. files `{type}.handlebars` and `{type}.subject.handlebars` will used
|
|
13
|
+
* @param payload - object with payload to build you mail
|
|
14
|
+
* @param attachments - array of files to attach to mail
|
|
15
|
+
* @param ttl - the number of seconds after which the message will be rejected from the queue if,
|
|
16
|
+
* but only if it was processed with an error. Set 0 if you think your message should live until
|
|
17
|
+
* it is successfully sent.
|
|
16
18
|
*/
|
|
17
19
|
sendMail<TResult = any>(to: string, type: string, payload?: {
|
|
18
20
|
[key: string]: unknown;
|
|
19
|
-
}, ttl?: number): Observable<TResult>;
|
|
21
|
+
}, ttl?: number, attachments?: Attachment[]): Observable<TResult>;
|
|
20
22
|
}
|
|
@@ -29,20 +29,22 @@ let MailService = class MailService {
|
|
|
29
29
|
this.logger.log('RMQ Connected');
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
|
-
* @param to
|
|
33
|
-
* @param type
|
|
34
|
-
* @param payload
|
|
35
|
-
* @param
|
|
36
|
-
*
|
|
37
|
-
*
|
|
32
|
+
* @param to - email to send the message to
|
|
33
|
+
* @param type - the type of message to send. files `{type}.handlebars` and `{type}.subject.handlebars` will used
|
|
34
|
+
* @param payload - object with payload to build you mail
|
|
35
|
+
* @param attachments - array of files to attach to mail
|
|
36
|
+
* @param ttl - the number of seconds after which the message will be rejected from the queue if,
|
|
37
|
+
* but only if it was processed with an error. Set 0 if you think your message should live until
|
|
38
|
+
* it is successfully sent.
|
|
38
39
|
*/
|
|
39
|
-
sendMail(to, type, payload, ttl = 0) {
|
|
40
|
+
sendMail(to, type, payload, ttl = 0, attachments) {
|
|
40
41
|
return this.client.emit('new_mail', {
|
|
41
42
|
type,
|
|
42
43
|
payload,
|
|
43
44
|
to,
|
|
44
45
|
timestamp: new Date().getTime(),
|
|
45
46
|
ttl,
|
|
47
|
+
attachments,
|
|
46
48
|
});
|
|
47
49
|
}
|
|
48
50
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.service.js","sourceRoot":"","sources":["../../src/connect/app.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4E;AAC5E,yDAA4D;AAC5D,+BAAyC;
|
|
1
|
+
{"version":3,"file":"app.service.js","sourceRoot":"","sources":["../../src/connect/app.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4E;AAC5E,yDAA4D;AAC5D,+BAAyC;AAEzC,8CAAwD;AAExD,mCAA4B;AAG5B,IAAa,WAAW,GAAxB,MAAa,WAAW;IAAxB;QACU,WAAM,GAAW,IAAI,eAAM,CAAC,mBAAmB,CAAC,CAAC;IA2C3D,CAAC;IAnCC,KAAK,CAAC,sBAAsB;QAC1B,MAAM,YAAK,CAAC,KAAK,IAAI,EAAE;YACrB,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YAC5B,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,CAAC;QACtC,CAAC,CAAC;aACC,IAAI,CAAC,eAAK,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;aACrB,SAAS,EAAE,CAAC;QACf,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IACnC,CAAC;IAED;;;;;;;;OAQG;IACH,QAAQ,CACN,EAAU,EACV,IAAY,EACZ,OAAoC,EACpC,MAAc,CAAC,EACf,WAA0B;QAE1B,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAuB,UAAU,EAAE;YACxD,IAAI;YACJ,OAAO;YACP,EAAE;YACF,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE;YAC/B,GAAG;YACH,WAAW;SACZ,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AAxCC;IADC,sBAAM,CAAC,0BAAa,CAAC;8BACd,2BAAW;2CAAC;AAGpB;IADC,sBAAM,CAAC,qBAAQ,CAAC;8BACD,2BAAW;mDAAC;AAPjB,WAAW;IADvB,mBAAU,EAAE;GACA,WAAW,CA4CvB;AA5CY,kCAAW"}
|
|
@@ -45,13 +45,22 @@ class SenderService {
|
|
|
45
45
|
async sendMail(to, template, context = {}, attachments) {
|
|
46
46
|
this.logger.debug(`New message to "${to}" with template "${template}"`);
|
|
47
47
|
const subjectTpl = Handlebars.compile(fs.readFileSync(`templates/${template}.subject.handlebars`).toString());
|
|
48
|
+
const fixedAttachments = attachments === null || attachments === void 0 ? void 0 : attachments.map((att) => {
|
|
49
|
+
if (Buffer.isBuffer(att.content)) {
|
|
50
|
+
return att;
|
|
51
|
+
}
|
|
52
|
+
if (att.content && att.encoding === 'base64') {
|
|
53
|
+
return Object.assign(Object.assign({}, att), { content: Buffer.from(att.content, 'base64') });
|
|
54
|
+
}
|
|
55
|
+
return att;
|
|
56
|
+
});
|
|
48
57
|
const info = await this.transporter.sendMail({
|
|
49
58
|
from: config_1.MAIL_SERVICE.SMTP.SENDER,
|
|
50
59
|
to,
|
|
51
60
|
subject: subjectTpl(context),
|
|
52
61
|
template,
|
|
53
62
|
context,
|
|
54
|
-
attachments,
|
|
63
|
+
attachments: fixedAttachments,
|
|
55
64
|
});
|
|
56
65
|
this.logger.debug(`Message sent: ${info.messageId}, ${info.response}`);
|
|
57
66
|
const isEthereal = config_1.MAIL_SERVICE.SMTP.HOST === 'smtp.ethereal.email';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sender.service.js","sourceRoot":"","sources":["../../src/service/sender.service.ts"],"names":[],"mappings":";;;AAAA,yBAAyB;AACzB,2CAAwC;AACxC,mCAAsC;AACtC,yCAAyC;AACzC,2CAAgG;AAChG,qDAAqD;AAGrD,MAAM,UAAU,GAAG;IACjB,UAAU,EAAE;QACV,UAAU,EAAE,YAAY;KACzB;IACD,QAAQ,EAAE,YAAY;CACvB,CAAC;AAEF,MAAa,aAAa;IAA1B;QAEmB,WAAM,GAAW,IAAI,eAAM,CAAC,qBAAqB,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"sender.service.js","sourceRoot":"","sources":["../../src/service/sender.service.ts"],"names":[],"mappings":";;;AAAA,yBAAyB;AACzB,2CAAwC;AACxC,mCAAsC;AACtC,yCAAyC;AACzC,2CAAgG;AAChG,qDAAqD;AAGrD,MAAM,UAAU,GAAG;IACjB,UAAU,EAAE;QACV,UAAU,EAAE,YAAY;KACzB;IACD,QAAQ,EAAE,YAAY;CACvB,CAAC;AAEF,MAAa,aAAa;IAA1B;QAEmB,WAAM,GAAW,IAAI,eAAM,CAAC,qBAAqB,CAAC,CAAC;IAiEtE,CAAC;IA/DC,KAAK,CAAC,YAAY;QAChB,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,OAAO;QACX,MAAM,UAAU,GAAG,qBAAY,CAAC,IAAI,CAAC,IAAI,KAAK,qBAAqB,CAAC;QACpE,IAAI,CAAC,qBAAY,CAAC,IAAI,CAAC,QAAQ,IAAI,CAAC,UAAU,EAAE;YAC9C,MAAM,IAAI,KAAK,CACb;qFAC6E,CAC9E,CAAC;SACH;QAED,IAAI,WAAW,CAAC;QAChB,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ACN,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,OAAiB,EAAE,QAAQ,CAAC,IACrD;aACH;YAED,OAAO,GAAG,CAAC;QACb,CAAC,CAAC,CAAC;QAEH,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC;YAC3C,IAAI,EAAE,qBAAY,CAAC,IAAI,CAAC,MAAM;YAC9B,EAAE;YACF,OAAO,EAAE,UAAU,CAAC,OAAO,CAAC;YAC5B,QAAQ;YACR,OAAO;YACP,WAAW,EAAE,gBAAgB;SAC9B,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,iBAAiB,IAAI,CAAC,SAAS,KAAK,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QACvE,MAAM,UAAU,GAAG,qBAAY,CAAC,IAAI,CAAC,IAAI,KAAK,qBAAqB,CAAC;QACpE,IAAI,UAAU,EAAE;YACd,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,gBAAgB,8BAAiB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;SAC9D;IACH,CAAC;CACF;AAnED,sCAmEC"}
|
|
@@ -2497,8 +2497,8 @@
|
|
|
2497
2497
|
"affectsGlobalScope": false
|
|
2498
2498
|
},
|
|
2499
2499
|
"../src/connect/app.service.ts": {
|
|
2500
|
-
"version": "
|
|
2501
|
-
"signature": "
|
|
2500
|
+
"version": "a24595f0b180371fdc60d842c5b23875afcff3b2b6d04f73f5803f1a320d92e8",
|
|
2501
|
+
"signature": "ae190d9aa297a057e29e225f55e4b34af5f3e76de907ee3d73eb8b63402f9d4c",
|
|
2502
2502
|
"affectsGlobalScope": false
|
|
2503
2503
|
},
|
|
2504
2504
|
"../src/connect/app.module.ts": {
|
|
@@ -2947,7 +2947,7 @@
|
|
|
2947
2947
|
"affectsGlobalScope": true
|
|
2948
2948
|
},
|
|
2949
2949
|
"../src/service/sender.service.ts": {
|
|
2950
|
-
"version": "
|
|
2950
|
+
"version": "d91351f039121f350600179add87236d4a503bc02c7200eaa0dcde1f642b3b60",
|
|
2951
2951
|
"signature": "9d42adcd455789e45848adcfe94505e1b2c401fdfcc3a62b8d6c216b415bd89f",
|
|
2952
2952
|
"affectsGlobalScope": false
|
|
2953
2953
|
},
|