Skip to content

Commit fe597e8

Browse files
committed
Update README, package and logo, 2.0.0v
1 parent fc83c3d commit fe597e8

File tree

4 files changed

+209
-36
lines changed

4 files changed

+209
-36
lines changed

README.md

+182-25
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<!-- PROJECT LOGO -->
2323
<br />
2424
<p align="center">
25-
<a href="https://github.com/othneildrew/Best-README-Template">
25+
<a href="https://github.com/macarthuror/parse-smtp-template">
2626
<img src="logo.png" alt="Logo" width="80" height="80" />
2727
</a>
2828

@@ -31,6 +31,7 @@
3131
<p align="center">
3232
An easy way to send email templates via SMTP with your <a href="https://github.com/parse-community/parse-server">Parse Server</a>!
3333
<br />
34+
<b>(Multi Language Support)</b>
3435
<br />
3536
<a href="https://github.com/macarthuror/parse-smtp-template/issues">Report Bug</a>
3637
·
@@ -49,6 +50,9 @@
4950
* [Prerequisites](#prerequisites)
5051
* [Installation](#installation)
5152
* [Usage](#usage)
53+
* [Simple template](#simple-template)
54+
* [Multi template](#multi-template)
55+
* [Multi language](#multi-languaje)
5256
* [Roadmap](#roadmap)
5357
* [Contributing](#contributing)
5458
* [License](#license)
@@ -62,9 +66,11 @@
6266

6367
<!-- [![Product Name Screen Shot][product-screenshot]](https://example.com) -->
6468

65-
This is a module maded it for Parse Server and an easy solution to send emails via SMTP with templates in HTML.
69+
This is a module made it for Parse Server and an easy solution to send emails via SMTP with templates in HTML, also with the posibility of use a multi language support for your templates.
6670

67-
We recomend to use the [Cerberus](https://github.com/TedGoas/Cerberus) for the email templates.
71+
We recomend you to use the [Cerberus](https://github.com/TedGoas/Cerberus) project for the email templates.
72+
73+
( if you know about other templates you can added )
6874

6975
### Built With
7076

@@ -75,8 +81,7 @@ We recomend to use the [Cerberus](https://github.com/TedGoas/Cerberus) for the e
7581
<!-- GETTING STARTED -->
7682
## Getting Started
7783

78-
This is an example of how you may give instructions on setting up your project locally.
79-
To get a local copy up and running follow these simple example steps.
84+
This module is a very simple solution and because of that you can get it up and running in a few minutes.
8085

8186
### Installation
8287

@@ -90,7 +95,7 @@ yarn
9095
```sh
9196
yarn add parse-smtp-template
9297
```
93-
2. In your Parse Server add the configuration of your email account
98+
2. In your Parse Server add the configuration of the emailAdapter and fill the requeriments to connect with your email account
9499

95100
```
96101
var api = new ParseServer({
@@ -102,36 +107,45 @@ var api = new ParseServer({
102107
host: "smtp.mail.com",
103108
user: "name@domain.com",
104109
password: "SecurePassword",
105-
fromAddress: 'app@domain.com',
106-
107-
// Optional Parameters
108-
template: true,
109-
templatePath: "views/templates/main.html",
110-
passwordSubject: "A custom password recovery Subject",
111-
confirmSubject: "A custom email confirmation Subject"
110+
fromAddress: 'app@domain.com'
112111
}
113112
}
114113
})
115114
```
116-
> Now is ready to use it!
115+
> Now is ready to use!
116+
117+
--
118+
<br />
117119

118120
3. (Optional) Config your email template
119121

120-
The templates have access to 4 parameters to send
122+
In this module you can choise to use a simple template (1 template for bouth emails) or multiTemplate (1 template per type of email)
123+
If you want to use the multi Language mode you need to set up the multi languaje mode.
124+
---
125+
126+
---
127+
<!-- USAGE EXAMPLES -->
128+
## Usage
129+
Use it, it´s very easy 😎😃👌
130+
131+
### Simple template
132+
133+
This template is used to send bouth email (password recovery and email confirmation)
134+
135+
The templates have access to 6 parameters :
121136
* link
122-
* username
137+
* btn
138+
* body
139+
* username
123140
* appName
124141
* subject
125142

126-
To use it you only need to write ${parameter} to use it on the email
143+
To use it you only need to write `${parameter}` on the template
127144

128145
**IMPORTANT** -- **All the HTML file need to use only double quotes to avoid problems**
129-
130-
<!-- USAGE EXAMPLES -->
131-
## Usage
132-
133-
To use a custome template is necessary to select the correct file.
134-
In this example we are gonna use `template.html``
146+
---
147+
If you want a custome template is necessary to select the correct file.
148+
In this example we are gonna use `template.html`
135149

136150
index.js
137151
```
@@ -140,11 +154,32 @@ emailAdapter: {
140154
options: {
141155
...
142156
template: true,
143-
templatePath: "views/templates/template.html"
157+
templatePath: "views/templates/template.html",
158+
159+
// Custome options to your emails
160+
// You can add more options if you need
161+
passwordOptions: {
162+
subject: "Password recovery",
163+
body: "Custome pasword recovery email body",
164+
btn: "Recover your password"
165+
/* --EXTRA PARAMETERS--
166+
others: {
167+
extraParameter
168+
}
169+
*/
170+
},
171+
confirmOptions: {
172+
subject: "E-mail confirmation",
173+
body: "Custome email confirmation body",
174+
btn: "confirm your email"
175+
},
144176
}
145177
}
146178
147179
```
180+
> To use the extra parameters please use `${options.extraParameter}`
181+
182+
148183
directory
149184
```
150185
project
@@ -174,8 +209,130 @@ project
174209
</tr>
175210
...
176211
```
177-
> You can look up the template is by default in the templates folder to get a better understanding
212+
> You can look up the template by default to get a better understanding
213+
214+
--
215+
### Multi template
216+
217+
This option is a better way to customize your emails because you are able to use a different template per type of email.
218+
219+
This template have access to 4 parameters:
220+
* user _(all the info of the _User object)_
221+
* link
222+
* appName
223+
* options
224+
225+
The __options__ parameter needs to have _subject, body_ and _btn_ like minimun
226+
227+
228+
index.js
229+
```
230+
emailAdapter: {
231+
module: 'parse-smtp-template',
232+
options: {
233+
...
234+
multiTemplate: true,
235+
confirmTemplatePath: "views/templates/confirmTemplate.html",
236+
passwordTemplatePath: "views/templates/passwordTemplate.html",
237+
238+
// Custome options to your emails
239+
// You can add as much as you need
240+
passwordOptions: {
241+
subject: "Password recovery",
242+
body: "Custome pasword recovery email body",
243+
btn: "Recover your password"
244+
/* --EXTRA PARAMETERS--
245+
others: {
246+
extraParameter
247+
}
248+
*/
249+
},
250+
confirmOptions: {
251+
subject: "E-mail confirmation",
252+
body: "Custome email confirmation body",
253+
btn: "confirm your email"
254+
},
255+
}
256+
}
257+
```
258+
> To use the extra parameters please use ${options.extraParameter}
259+
260+
--
261+
### Multi language
178262

263+
To be able to use Multi languaje is necesary set true `multiTemplate` and `multiLang`.
264+
265+
index.js
266+
```
267+
emailAdapter: {
268+
module: 'parse-smtp-template',
269+
options: {
270+
...
271+
multiTemplate: true,
272+
confirmTemplatePath: "views/templates/confirmTemplate.html",
273+
passwordTemplatePath: "views/templates/passwordTemplate.html",
274+
multiLang: true,
275+
multiLangPass: {
276+
es: {
277+
subject: "Recuperación de Contraseña",
278+
body: "Cuerpo del correo de recuperación de contrseña",
279+
btn: "recupera tu contraseña"
280+
/* --EXTRA PARAMETERS--
281+
others: {
282+
extraParameter
283+
}
284+
*/
285+
},
286+
en: {
287+
subject: "Password recovery",
288+
body: "Password recovery email body",
289+
btn: "Recover your password"
290+
},
291+
fr: {
292+
subject: "Récupération du mot de passe",
293+
body: "Corps de l'e-mail de récupération de mot de passe",
294+
btn: "récupérer votre mot de passe"
295+
}
296+
},
297+
298+
multiLangConfirm: {
299+
es: {
300+
subject: "Confirmación de Correo",
301+
body: "Cuerpo del correo de confirmación de correo",
302+
btn: "confirma tu correo"
303+
},
304+
en: {
305+
subject: "E-mail confirmation",
306+
body: "Mail confirmation email body",
307+
btn: "confirm your email"
308+
},
309+
fr: {
310+
subject: "Mail de confirmation",
311+
body: "Courriel de confirmation du corps de l'e-mail",
312+
btn: "confirmez votre email"
313+
}
314+
},
315+
316+
// Default options if the lang of the user isn´t in some of the multiLanguage objects
317+
passwordOptions: {
318+
subject: "Password recovery",
319+
body: "Custome pasword recovery email body",
320+
btn: "Recover your password"
321+
/* --EXTRA PARAMETERS--
322+
others: {
323+
extraParameter
324+
}
325+
*/
326+
},
327+
confirmOptions: {
328+
subject: "E-mail confirmation",
329+
body: "Custome email confirmation body",
330+
btn: "confirm your email"
331+
},
332+
}
333+
}
334+
```
335+
---
179336
<!-- ROADMAP -->
180337
## Roadmap
181338

index.js

+25-9
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ var SmtpMailAdapter = mailOptions => {
109109
? passwordOptions.btn || "Reset Password"
110110
: confirmOptions.btn || "Confirm Email";
111111

112+
let options = mail.subject.indexOf("Password") !=-1
113+
? passwordOptions.others || {}
114+
: confirmOptions.others || {};
115+
112116
if (_templates) {
113117
filePath = path.join("./", _templatePath);
114118
template = eval('`' + fs.readFileSync(filePath).toString() + '`');
@@ -170,25 +174,31 @@ var SmtpMailAdapter = mailOptions => {
170174
throw "You need to add a template for the confirmation emails and pass the options";
171175
} else if(_multiLang && !mailOptions.multiLangConfirm) {
172176
throw "To use multiLang in the templates needs to pass the multiLangPass object with the translations";
177+
} else if(!mailOptions.confirmOptions
178+
|| !mailOptions.confirmOptions.subject
179+
|| !mailOptions.confirmOptions.body
180+
|| !mailOptions.confirmOptions.btn) {
181+
throw "You need to set the 'confirmOptions' object with subject, body and btn"
173182
}
174183

175184
const user = data.user.attributes;
176185
const link = data.link;
177186
const appName = data.appName;
178-
const options = mailOptions.confirmOptions;
187+
const defOptions = mailOptions.confirmOptions;
188+
const options = mailOptions.passwordOptions.others || {};
179189
const langOptions = mailOptions.multiLangConfirm[user.lang];
180190

181191
let subject = (_multiLang && typeof langOptions !== 'undefined')
182192
? langOptions.subject
183-
: options.subject
193+
: defOptions.subject
184194

185195
let body = (_multiLang && typeof langOptions !== 'undefined')
186196
? langOptions.body
187-
: options.body
197+
: defOptions.body
188198

189199
let btn = (_multiLang && typeof langOptions !== 'undefined')
190200
? langOptions.btn
191-
: options.btn
201+
: defOptions.btn
192202

193203
let filePath = path.join("./", mailOptions.confirmTemplatePath);
194204
let template = eval('`' + fs.readFileSync(filePath).toString() + '`');
@@ -245,25 +255,31 @@ var SmtpMailAdapter = mailOptions => {
245255
throw "You need to add a template for the password recovery emails";
246256
} else if(_multiLang && !mailOptions.multiLangPass) {
247257
throw "To use multiLang in the templates needs to pass the multiLangPass object with the translations";
248-
}
258+
} else if(!mailOptions.passwordOptions
259+
|| !mailOptions.passwordOptions.subject
260+
|| !mailOptions.passwordOptions.body
261+
|| !mailOptions.passwordOptions.btn) {
262+
throw "You need to set the 'passwordOptions' object with subject, body and btn"
263+
}
249264

250265
const user = data.user.attributes;
251266
const link = data.link;
252267
const appName = data.appName;
253-
const options = mailOptions.passwordOptions;
268+
const defOptions = mailOptions.passwordOptions;
269+
const options = mailOptions.passwordOptions.others || {};
254270
const langOptions = mailOptions.multiLangPass[user.lang];
255271

256272
let subject = (_multiLang && typeof langOptions !== 'undefined')
257273
? langOptions.subject
258-
: options.subject
274+
: defOptions.subject
259275

260276
let body = (_multiLang && typeof langOptions !== 'undefined')
261277
? langOptions.body
262-
: options.body
278+
: defOptions.body
263279

264280
let btn = (_multiLang && typeof langOptions !== 'undefined')
265281
? langOptions.btn
266-
: options.btn
282+
: defOptions.btn
267283

268284
let filePath = path.join("./", mailOptions.passwordTemplatePath);
269285
let template = eval('`' + fs.readFileSync(filePath).toString() + '`');

logo.png

8.36 KB
Loading

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "parse-smtp-template",
3-
"version": "1.0.0",
4-
"description": "Parse Server Module to easy send emails via SMTP with a customizable template option",
3+
"version": "2.0.0",
4+
"description": "Parse Server Module to send emails via SMTP with a customizable template option and Multi Language",
55
"main": "index.js",
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1"

0 commit comments

Comments
 (0)