diff --git a/README.md b/README.md
index 6bb6e84..9c8910f 100644
--- a/README.md
+++ b/README.md
@@ -22,7 +22,7 @@
- + @@ -31,6 +31,7 @@
An easy way to send email templates via SMTP with your Parse Server!
+ (Multi Language Support)
Report Bug
·
@@ -49,6 +50,9 @@
* [Prerequisites](#prerequisites)
* [Installation](#installation)
* [Usage](#usage)
+ * [Simple template](#simple-template)
+ * [Multi template](#multi-template)
+ * [Multi language](#multi-languaje)
* [Roadmap](#roadmap)
* [Contributing](#contributing)
* [License](#license)
@@ -62,9 +66,11 @@
-This is a module maded it for Parse Server and an easy solution to send emails via SMTP with templates in HTML.
+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.
-We recomend to use the [Cerberus](https://github.com/TedGoas/Cerberus) for the email templates.
+We recomend you to use the [Cerberus](https://github.com/TedGoas/Cerberus) project for the email templates.
+
+( if you know about other templates you can added )
### Built With
@@ -75,8 +81,7 @@ We recomend to use the [Cerberus](https://github.com/TedGoas/Cerberus) for the e
## Getting Started
-This is an example of how you may give instructions on setting up your project locally.
-To get a local copy up and running follow these simple example steps.
+This module is a very simple solution and because of that you can get it up and running in a few minutes.
### Installation
@@ -90,7 +95,7 @@ yarn
```sh
yarn add parse-smtp-template
```
-2. In your Parse Server add the configuration of your email account
+2. In your Parse Server add the configuration of the emailAdapter and fill the requeriments to connect with your email account
```
var api = new ParseServer({
@@ -102,36 +107,45 @@ var api = new ParseServer({
host: "smtp.mail.com",
user: "name@domain.com",
password: "SecurePassword",
- fromAddress: 'app@domain.com',
-
- // Optional Parameters
- template: true,
- templatePath: "views/templates/main.html",
- passwordSubject: "A custom password recovery Subject",
- confirmSubject: "A custom email confirmation Subject"
+ fromAddress: 'app@domain.com'
}
}
})
```
-> Now is ready to use it!
+> Now is ready to use!
+
+--
+
3. (Optional) Config your email template
-The templates have access to 4 parameters to send
+In this module you can choise to use a simple template (1 template for bouth emails) or multiTemplate (1 template per type of email)
+If you want to use the multi Language mode you need to set up the multi languaje mode.
+---
+
+---
+
+## Usage
+Use it, it´s very easy 😎😃👌
+
+### Simple template
+
+This template is used to send bouth email (password recovery and email confirmation)
+
+The templates have access to 6 parameters :
* link
-* username
+* btn
+* body
+* username
* appName
* subject
-To use it you only need to write ${parameter} to use it on the email
+To use it you only need to write `${parameter}` on the template
**IMPORTANT** -- **All the HTML file need to use only double quotes to avoid problems**
-
-
-## Usage
-
-To use a custome template is necessary to select the correct file.
-In this example we are gonna use `template.html``
+---
+If you want a custome template is necessary to select the correct file.
+In this example we are gonna use `template.html`
index.js
```
@@ -140,11 +154,32 @@ emailAdapter: {
options: {
...
template: true,
- templatePath: "views/templates/template.html"
+ templatePath: "views/templates/template.html",
+
+ // Custome options to your emails
+ // You can add more options if you need
+ passwordOptions: {
+ subject: "Password recovery",
+ body: "Custome pasword recovery email body",
+ btn: "Recover your password"
+ /* --EXTRA PARAMETERS--
+ others: {
+ extraParameter
+ }
+ */
+ },
+ confirmOptions: {
+ subject: "E-mail confirmation",
+ body: "Custome email confirmation body",
+ btn: "confirm your email"
+ },
}
}
```
+> To use the extra parameters please use `${options.extraParameter}`
+
+
directory
```
project
@@ -174,8 +209,130 @@ project
...
```
-> You can look up the template is by default in the templates folder to get a better understanding
+> You can look up the template by default to get a better understanding
+
+--
+### Multi template
+
+This option is a better way to customize your emails because you are able to use a different template per type of email.
+
+This template have access to 4 parameters:
+* user _(all the info of the _User object)_
+* link
+* appName
+* options
+
+The __options__ parameter needs to have _subject, body_ and _btn_ like minimun
+
+
+index.js
+```
+emailAdapter: {
+ module: 'parse-smtp-template',
+ options: {
+ ...
+ multiTemplate: true,
+ confirmTemplatePath: "views/templates/confirmTemplate.html",
+ passwordTemplatePath: "views/templates/passwordTemplate.html",
+
+ // Custome options to your emails
+ // You can add as much as you need
+ passwordOptions: {
+ subject: "Password recovery",
+ body: "Custome pasword recovery email body",
+ btn: "Recover your password"
+ /* --EXTRA PARAMETERS--
+ others: {
+ extraParameter
+ }
+ */
+ },
+ confirmOptions: {
+ subject: "E-mail confirmation",
+ body: "Custome email confirmation body",
+ btn: "confirm your email"
+ },
+ }
+}
+```
+> To use the extra parameters please use ${options.extraParameter}
+
+--
+### Multi language
+To be able to use Multi languaje is necesary set true `multiTemplate` and `multiLang`.
+
+index.js
+```
+emailAdapter: {
+ module: 'parse-smtp-template',
+ options: {
+ ...
+ multiTemplate: true,
+ confirmTemplatePath: "views/templates/confirmTemplate.html",
+ passwordTemplatePath: "views/templates/passwordTemplate.html",
+ multiLang: true,
+ multiLangPass: {
+ es: {
+ subject: "Recuperación de Contraseña",
+ body: "Cuerpo del correo de recuperación de contrseña",
+ btn: "recupera tu contraseña"
+ /* --EXTRA PARAMETERS--
+ others: {
+ extraParameter
+ }
+ */
+ },
+ en: {
+ subject: "Password recovery",
+ body: "Password recovery email body",
+ btn: "Recover your password"
+ },
+ fr: {
+ subject: "Récupération du mot de passe",
+ body: "Corps de l'e-mail de récupération de mot de passe",
+ btn: "récupérer votre mot de passe"
+ }
+ },
+
+ multiLangConfirm: {
+ es: {
+ subject: "Confirmación de Correo",
+ body: "Cuerpo del correo de confirmación de correo",
+ btn: "confirma tu correo"
+ },
+ en: {
+ subject: "E-mail confirmation",
+ body: "Mail confirmation email body",
+ btn: "confirm your email"
+ },
+ fr: {
+ subject: "Mail de confirmation",
+ body: "Courriel de confirmation du corps de l'e-mail",
+ btn: "confirmez votre email"
+ }
+ },
+
+ // Default options if the lang of the user isn´t in some of the multiLanguage objects
+ passwordOptions: {
+ subject: "Password recovery",
+ body: "Custome pasword recovery email body",
+ btn: "Recover your password"
+ /* --EXTRA PARAMETERS--
+ others: {
+ extraParameter
+ }
+ */
+ },
+ confirmOptions: {
+ subject: "E-mail confirmation",
+ body: "Custome email confirmation body",
+ btn: "confirm your email"
+ },
+ }
+}
+```
+---
## Roadmap
diff --git a/index.js b/index.js
index 7b76a30..997c889 100644
--- a/index.js
+++ b/index.js
@@ -109,6 +109,10 @@ var SmtpMailAdapter = mailOptions => {
? passwordOptions.btn || "Reset Password"
: confirmOptions.btn || "Confirm Email";
+ let options = mail.subject.indexOf("Password") !=-1
+ ? passwordOptions.others || {}
+ : confirmOptions.others || {};
+
if (_templates) {
filePath = path.join("./", _templatePath);
template = eval('`' + fs.readFileSync(filePath).toString() + '`');
@@ -170,25 +174,31 @@ var SmtpMailAdapter = mailOptions => {
throw "You need to add a template for the confirmation emails and pass the options";
} else if(_multiLang && !mailOptions.multiLangConfirm) {
throw "To use multiLang in the templates needs to pass the multiLangPass object with the translations";
+ } else if(!mailOptions.confirmOptions
+ || !mailOptions.confirmOptions.subject
+ || !mailOptions.confirmOptions.body
+ || !mailOptions.confirmOptions.btn) {
+ throw "You need to set the 'confirmOptions' object with subject, body and btn"
}
const user = data.user.attributes;
const link = data.link;
const appName = data.appName;
- const options = mailOptions.confirmOptions;
+ const defOptions = mailOptions.confirmOptions;
+ const options = mailOptions.passwordOptions.others || {};
const langOptions = mailOptions.multiLangConfirm[user.lang];
let subject = (_multiLang && typeof langOptions !== 'undefined')
? langOptions.subject
- : options.subject
+ : defOptions.subject
let body = (_multiLang && typeof langOptions !== 'undefined')
? langOptions.body
- : options.body
+ : defOptions.body
let btn = (_multiLang && typeof langOptions !== 'undefined')
? langOptions.btn
- : options.btn
+ : defOptions.btn
let filePath = path.join("./", mailOptions.confirmTemplatePath);
let template = eval('`' + fs.readFileSync(filePath).toString() + '`');
@@ -245,25 +255,31 @@ var SmtpMailAdapter = mailOptions => {
throw "You need to add a template for the password recovery emails";
} else if(_multiLang && !mailOptions.multiLangPass) {
throw "To use multiLang in the templates needs to pass the multiLangPass object with the translations";
- }
+ } else if(!mailOptions.passwordOptions
+ || !mailOptions.passwordOptions.subject
+ || !mailOptions.passwordOptions.body
+ || !mailOptions.passwordOptions.btn) {
+ throw "You need to set the 'passwordOptions' object with subject, body and btn"
+}
const user = data.user.attributes;
const link = data.link;
const appName = data.appName;
- const options = mailOptions.passwordOptions;
+ const defOptions = mailOptions.passwordOptions;
+ const options = mailOptions.passwordOptions.others || {};
const langOptions = mailOptions.multiLangPass[user.lang];
let subject = (_multiLang && typeof langOptions !== 'undefined')
? langOptions.subject
- : options.subject
+ : defOptions.subject
let body = (_multiLang && typeof langOptions !== 'undefined')
? langOptions.body
- : options.body
+ : defOptions.body
let btn = (_multiLang && typeof langOptions !== 'undefined')
? langOptions.btn
- : options.btn
+ : defOptions.btn
let filePath = path.join("./", mailOptions.passwordTemplatePath);
let template = eval('`' + fs.readFileSync(filePath).toString() + '`');
diff --git a/logo.png b/logo.png
new file mode 100644
index 0000000..ab1a1be
Binary files /dev/null and b/logo.png differ
diff --git a/package.json b/package.json
index 526a625..2020b4a 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "parse-smtp-template",
- "version": "1.0.0",
- "description": "Parse Server Module to easy send emails via SMTP with a customizable template option",
+ "version": "2.0.0",
+ "description": "Parse Server Module to send emails via SMTP with a customizable template option and Multi Language",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"