@spinajs/email-smtp-transport 2.0.38 → 2.0.45

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/lib/index.d.ts CHANGED
@@ -0,0 +1,16 @@
1
+ import { Log } from '@spinajs/log';
2
+ import { IEmail, EmailSender, EmailConnectionOptions } from '@spinajs/email';
3
+ import { Templates } from '@spinajs/templates';
4
+ import * as nodemailer from 'nodemailer';
5
+ import { fs } from '@spinajs/fs';
6
+ export declare class EmailSenderSmtp extends EmailSender {
7
+ Options: EmailConnectionOptions;
8
+ protected Log: Log;
9
+ protected Tempates: Templates;
10
+ protected FileSystems: Map<string, fs>;
11
+ protected DefaultFileProvider: string;
12
+ protected Transporter: nodemailer.Transporter;
13
+ constructor(Options: EmailConnectionOptions);
14
+ resolve(): Promise<void>;
15
+ send(email: IEmail): Promise<void>;
16
+ }
package/lib/index.js CHANGED
@@ -1,79 +1,136 @@
1
- // import { IOFail } from '@spinajs/exceptions';
2
- // import { Autoinject, Injectable, NewInstance } from '@spinajs/di';
3
- // import { Log, Logger } from '@spinajs/log';
4
- // import { Email, EmailSender, EmailConnectionOptions } from '@spinajs/email';
5
- // import { Templates } from '@spinajs/templates';
6
- // import * as nodemailer from 'nodemailer';
7
- // import { fs } from '@spinajs/fs';
8
- // import _ from 'lodash';
9
- // @Injectable()
10
- // @NewInstance()
11
- // export class EmailSenderSmtp extends EmailSender {
12
- // @Logger('email')
13
- // protected Log: Log;
14
- // @Autoinject(Templates)
15
- // protected Tempates: Templates;
16
- // @Autoinject(fs, (x) => x.Provider)
17
- // protected FileSystems: Map<string, fs>;
18
- // protected Transporter: nodemailer.Transport;
19
- // constructor(public Options: EmailConnectionOptions) {
20
- // super();
21
- // }
22
- // public async resolveAsync(): Promise<void> {
23
- // // create reusable transporter object using the default SMTP transport
24
- // this.Transporter = nodemailer.createTransport(
25
- // Object.assign(
26
- // {
27
- // host: this.Options.host,
28
- // port: this.Options.port,
29
- // secure: this.Options.ssl, // true for 465, false for other ports
30
- // auth: {
31
- // user: this.Options.login, // generated ethereal user
32
- // pass: this.Options.password, // generated ethereal password
33
- // },
34
- // },
35
- // // all additional options merged
36
- // this.Options.options,
37
- // ),
38
- // );
39
- // }
40
- // public async send(email: Email): Promise<void> {
41
- // const options = {
42
- // from: email.from, // sender address
43
- // to: email.to.join(','), // list of receivers
44
- // cc: email.cc ? email.cc.join(',') : null,
45
- // bcc: email.bcc ? email.bcc.join(',') : null,
46
- // replyTo: email.replyTo,
47
- // subject: email.subject, // Subject line
48
- // text: email.text, // plain text body
49
- // html: email.template ? await this.Tempates.render(email.template, email.model, email.lang) : null,
50
- // attachments: await Promise.all(
51
- // email.attachements.map(async (a) => {
52
- // // we allow to use multiple file sources, default is local
53
- // const provider = this.FileSystems.get(a.provider ?? 'fs-local');
54
- // if (!provider) {
55
- // throw new IOFail(`Filesystem privider for ${a.provider} not registered. Make sure you importer all required fs providers`);
56
- // }
57
- // // with local filesystem, it just return original path
58
- // // other implementations should dodwnload file locally,
59
- // // and return temporary path
60
- // // we provide path to file, becouse nodemailer
61
- // // prefer it when sending bigger files
62
- // const file = await provider.download(a.path);
63
- // return {
64
- // filename: a.name,
65
- // path: file,
66
- // provider: provider.Provider,
67
- // };
68
- // }),
69
- // ),
70
- // };
71
- // let message = await this.Transporter.sendMail(options);
72
- // const response = await this.Transporter.send(message);
73
- // // delete all downloaded files for attachement
74
- // const fsLocal = this.FileSystems.get('fs-local');
75
- // await Promise.all(options.attachments.filter((x) => x.provider !== 'fs-local').map((x) => fsLocal.unlink(x.path)));
76
- // this.Log.trace(`Sent email with data: ${JSON.stringify(_.pick(email, ['from', 'to', 'cc', 'bcc', 'replyTo', 'subject']))}, SMTP response: ${JSON.stringify(response)}`);
77
- // }
78
- // }
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
23
+ };
24
+ var __importStar = (this && this.__importStar) || function (mod) {
25
+ if (mod && mod.__esModule) return mod;
26
+ var result = {};
27
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28
+ __setModuleDefault(result, mod);
29
+ return result;
30
+ };
31
+ var __metadata = (this && this.__metadata) || function (k, v) {
32
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.EmailSenderSmtp = void 0;
39
+ const exceptions_1 = require("@spinajs/exceptions");
40
+ const di_1 = require("@spinajs/di");
41
+ const log_1 = require("@spinajs/log");
42
+ const email_1 = require("@spinajs/email");
43
+ const templates_1 = require("@spinajs/templates");
44
+ const nodemailer = __importStar(require("nodemailer"));
45
+ const fs_1 = require("@spinajs/fs");
46
+ const lodash_1 = __importDefault(require("lodash"));
47
+ const configuration_1 = require("@spinajs/configuration");
48
+ let EmailSenderSmtp = class EmailSenderSmtp extends email_1.EmailSender {
49
+ constructor(Options) {
50
+ super();
51
+ this.Options = Options;
52
+ }
53
+ async resolve() {
54
+ // create reusable transporter object using the default SMTP transport
55
+ this.Transporter = nodemailer.createTransport(Object.assign({
56
+ host: this.Options.host,
57
+ port: this.Options.port,
58
+ secure: this.Options.ssl,
59
+ auth: {
60
+ user: this.Options.user,
61
+ pass: this.Options.pass, // generated ethereal password
62
+ },
63
+ },
64
+ // all additional options merged
65
+ this.Options.options));
66
+ const result = await this.Transporter.verify();
67
+ if (!result) {
68
+ throw new Error(`cannot send smtp emails, varify() failed. Pleas check email smtp configuration for connection ${this.Options.name}`);
69
+ }
70
+ this.Log.success(`Email smtp connection ${this.Options.name} on host ${this.Options.host} established !`);
71
+ }
72
+ async send(email) {
73
+ const options = {
74
+ from: email.from,
75
+ to: email.to.join(','),
76
+ cc: email.cc ? email.cc.join(',') : null,
77
+ bcc: email.bcc ? email.bcc.join(',') : null,
78
+ replyTo: email.replyTo,
79
+ subject: email.subject,
80
+ text: email.text,
81
+ html: email.template ? await this.Tempates.render(email.template, email.model, email.lang) : null,
82
+ attachments: [],
83
+ };
84
+ if (email.attachements) {
85
+ options.attachments = await Promise.all(email.attachements.map(async (a) => {
86
+ var _a;
87
+ // we allow to use multiple file sources, default is local
88
+ const provider = this.FileSystems.get((_a = a.provider) !== null && _a !== void 0 ? _a : this.DefaultFileProvider);
89
+ if (!provider) {
90
+ throw new exceptions_1.IOFail(`Filesystem provider for ${a.provider} not registered. Make sure you importer all required fs providers`);
91
+ }
92
+ // with local filesystem, it just return original path
93
+ // other implementations should dodwnload file locally,
94
+ // and return temporary path
95
+ // we provide path to file, becouse nodemailer
96
+ // prefer it when sending bigger files
97
+ const file = await provider.download(a.path);
98
+ return {
99
+ filename: a.name,
100
+ path: file,
101
+ provider: provider.Name,
102
+ };
103
+ }));
104
+ }
105
+ let message = await this.Transporter.sendMail(options);
106
+ // delete all downloaded files for attachement
107
+ // all non local files are downloaded
108
+ // and temporary path is in email attachement path property
109
+ const fsLocal = this.FileSystems.get('fs-local');
110
+ await Promise.all(options.attachments.filter((x) => x.provider !== 'fs-local').map((x) => fsLocal.unlink(x.path)));
111
+ this.Log.trace(`Sent email with data: ${JSON.stringify(lodash_1.default.pick(email, ['from', 'to', 'cc', 'bcc', 'replyTo', 'subject']))}, SMTP response: ${JSON.stringify(message)}`);
112
+ }
113
+ };
114
+ __decorate([
115
+ (0, log_1.Logger)('email'),
116
+ __metadata("design:type", log_1.Log)
117
+ ], EmailSenderSmtp.prototype, "Log", void 0);
118
+ __decorate([
119
+ (0, di_1.Autoinject)(templates_1.Templates),
120
+ __metadata("design:type", templates_1.Templates)
121
+ ], EmailSenderSmtp.prototype, "Tempates", void 0);
122
+ __decorate([
123
+ (0, configuration_1.AutoinjectService)('fs.providers', fs_1.fs),
124
+ __metadata("design:type", Map)
125
+ ], EmailSenderSmtp.prototype, "FileSystems", void 0);
126
+ __decorate([
127
+ (0, configuration_1.Config)('fs.default'),
128
+ __metadata("design:type", String)
129
+ ], EmailSenderSmtp.prototype, "DefaultFileProvider", void 0);
130
+ EmailSenderSmtp = __decorate([
131
+ (0, di_1.Injectable)(email_1.EmailSender),
132
+ (0, di_1.PerInstanceCheck)(),
133
+ __metadata("design:paramtypes", [Object])
134
+ ], EmailSenderSmtp);
135
+ exports.EmailSenderSmtp = EmailSenderSmtp;
79
136
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,qEAAqE;AACrE,8CAA8C;AAC9C,+EAA+E;AAC/E,kDAAkD;AAClD,4CAA4C;AAC5C,oCAAoC;AACpC,0BAA0B;AAE1B,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  "description": "sending emails easy & reliable way",
5
5
  "main": "lib/index.js",
6
6
  "private": false,
7
7
  "scripts": {
8
- "build": "npm run clean && npm run compile && cpx src/views/**/* lib/views && cpx src/static/**/* lib/static",
8
+ "build": "npm run clean && npm run compile",
9
9
  "compile": "tsc -p tsconfig.build.json",
10
10
  "clean": "",
11
11
  "test": "ts-mocha -p tsconfig.json test/**/*.test.ts",
@@ -38,19 +38,24 @@
38
38
  },
39
39
  "homepage": "https://github.com/spinajs/main#readme",
40
40
  "devDependencies": {
41
- "@types/luxon": "^2.3.1",
41
+ "@spinajs/templates-handlebars": "^2.0.45",
42
+ "@spinajs/templates-pug": "^2.0.45",
43
+ "@types/luxon": "^3.2.0",
42
44
  "@types/node": "^16.11.11",
43
45
  "@types/nodemailer": "^6.4.4"
44
46
  },
45
47
  "dependencies": {
46
- "@spinajs/configuration": "^2.0.38",
47
- "@spinajs/di": "^2.0.38",
48
- "@spinajs/exceptions": "^2.0.12",
49
- "@spinajs/internal-logger": "^2.0.38",
50
- "@spinajs/intl": "^2.0.38",
51
- "@spinajs/log": "^2.0.38",
52
- "luxon": "^2.3.0",
48
+ "@spinajs/configuration": "^2.0.45",
49
+ "@spinajs/di": "^2.0.45",
50
+ "@spinajs/email": "^2.0.45",
51
+ "@spinajs/exceptions": "^2.0.39",
52
+ "@spinajs/fs": "^2.0.45",
53
+ "@spinajs/internal-logger": "^2.0.45",
54
+ "@spinajs/intl": "^2.0.45",
55
+ "@spinajs/log": "^2.0.45",
56
+ "@spinajs/templates": "^2.0.45",
57
+ "luxon": "^3.2.1",
53
58
  "nodemailer": "^6.7.7"
54
59
  },
55
- "gitHead": "5ea5440ee9db49595f531592ebdbc6d69f457082"
60
+ "gitHead": "3aa423c570eae952dc79fe6a4704c3d2ccc178be"
56
61
  }