Giter Site home page Giter Site logo

macarthuror / parse-smtp-template Goto Github PK

View Code? Open in Web Editor NEW
19.0 2.0 21.0 273 KB

Parse Server Module to easy send emails via SMTP with a customizable template option

License: MIT License

JavaScript 48.09% HTML 51.91%
parse-server smtp multi-language multi-template parse-smtp-template

parse-smtp-template's Introduction


Logo

Parse SMTP Template

An easy way to send email templates via SMTP with your Parse Server!
(Multi Language Support)
npm version total downloads monthly downloads
contributors license
Report Bug · Request Feature

FOSSA Status

Table of Contents

About The Project

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 you to use the Cerberus project for the email templates.

( if you know about other templates you can added )

Built With

Getting Started

This module is a very simple solution and because of that you can get it up and running in a few minutes.

Installation

  1. Install the package

npm

npm i parse-smtp-template

yarn

yarn add parse-smtp-template
  1. In your Parse Server add the configuration of the emailAdapter and fill the requeriments to connect with your email account
var api = new ParseServer({
    ...
    emailAdapter: {
        module: 'parse-smtp-template',
        options: {
            port: 587,
            host: "smtp.mail.com",
            user: "[email protected]",
            password: "SecurePassword",
            fromAddress: '[email protected]'
        }
    }
})

Now is ready to use!

--

  1. (Optional) Config your email template

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
  • btn
  • body
  • username
  • appName
  • subject
  • options (optional)

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

If you want a custome template is necessary to select the correct file. In this example we are gonna use template.html

index.js

emailAdapter: {
  module: 'parse-smtp-template',
  options: {
    ...
    template: true,
    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
│   index.js   
│
└─ views
│   └─ templates
│       └─ template.html
|
└─ node_modules
|

template.html

...
<tr>
  <td style="padding: 20px; font-family: sans-serif; font-size: 15px; line-height: 20px; color: #555555;">
  <h1 style="margin: 0 0 10px; font-size: 25px; line-height: 30px; color: #333333; font-weight: normal;">  ${subject}  </h1>
  <br>
  <ul style="padding: 0; margin: 0; list-style-type: disc;">
  <li style="margin:0 0 10px 30px;" class="list-item-first">App name: <b>  ${appName}  </b></li>
  <li style="margin:0 0 10px 30px;">Username: <b>  ${username}  </b></li>
  <li style="margin: 0 0 10px 30px;">link:</li>
  <li style="margin: 0 0 0 30px;" class="list-item-last">  ${link}  </li>
  </ul>
  </td>
</tr>
...

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 7 parameters:

  • user (all the info of the User object)
  • link
  • appName
  • subject
  • body
  • btn
  • options (optional)

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 language is necesary set multiTemplate and multiLang true and pass the column name where the language is stored in the multiLangColumn option. Default of multiLangColumn is lang.

multiLangColumn and the object needs to have the same value.

index.js

emailAdapter: {
  module: 'parse-smtp-template',
  options: {
    ...
    multiTemplate: true,
    confirmTemplatePath: "views/templates/confirmTemplate.html",
    passwordTemplatePath: "views/templates/passwordTemplate.html",
    multiLang: true,
    multiLangColumn: "language", // Default is "lang".
    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

See the open issues for a list of proposed features (and known issues).

Contributors

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Arturo Ortega - @MacarthurOr - [email protected]

Project Link: https://github.com/macarthuror/parse-smtp-template

Acknowledgements

parse-smtp-template's People

Contributors

fossabot avatar isokosan avatar macarthuror avatar oproulx avatar riccardoch avatar vince1995 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

parse-smtp-template's Issues

Multi language "others" parameters issue

When trying to use multi-language and multi templates, I get the following error

error: Uncaught internal server error. Cannot read properties of undefined (reading 'others') {"stack":"TypeError: Cannot read properties of undefined (reading 'others')\n at Object.sendPasswordResetEmail (C:\\Users\\megla\\AppData\\Roaming\\npm\\node_modules\\parse-smtp-template\\index.js:275:119)\n at UserController.sendPasswordResetEmail (C:\\Users\\megla\\AppData\\Roaming\\npm\\node_modules\\parse-server\\lib\\Controllers\\UserController.js:303:20)\n at processTicksAndRejections (node:internal/process/task_queues:96:5)"} TypeError: Cannot read properties of undefined (reading 'others') at Object.sendPasswordResetEmail (C:\Users\megla\AppData\Roaming\npm\node_modules\parse-smtp-template\index.js:275:119) at UserController.sendPasswordResetEmail (C:\Users\megla\AppData\Roaming\npm\node_modules\parse-server\lib\Controllers\UserController.js:303:20) at processTicksAndRejections (node:internal/process/task_queues:96:5)

did follow the same instructions in the ReadMe

I keep getting the same error with and without "others"

using signal template works without any issue.

I would also like to know something, how can you determine the language of the receiver? also, a feature request would be to create multiple files for each language since those are mostly static why not just pick a single file for each language instead.

TLS error for self-signed certificates

Started getting the following error:

Error: self-signed certificate
    at TLSSocket.onConnectSecure (node:_tls_wrap:1535:34)
    at TLSSocket.emit (node:events:513:28)
    at TLSSocket.emit (node:domain:489:12)
    at TLSSocket._finishInit (node:_tls_wrap:949:8)
    at ssl.onhandshakedone (node:_tls_wrap:733:12)

Looks like this is due to gmail having self-signed certificates.
The following fix solves the issue:

tls: {
      minVersion: 'TLSv1',
      rejectUnauthorized: false // This is required since google self-signs their cert
    }

However, it could be good for the module to have the tls settings configurable.

Parse server crashes if mail doesn't exist

I'm encountering a problem with this lib, whenever a user signs up with an email /domain that does not exist, the entire parse server just crashes, I'm guessing it's because it's trying to send to an unknown or invalid domain
Maybe a try catch would fix that, or maybe an exception needs to be made for OVH idk

Here is the error I get:

Error: queryA ETIMEOUT ssl0.ovh.net
     at QueryReqWrap.onresolve [as oncomplete] (node:dns:213:19) {
   errno: undefined,
   code: 'EDNS',
   syscall: 'queryA',
   hostname: 'ssl0.ovh.net',
   command: 'CONN'
 }

username is not defined when used multiTemplate

hello, I used "parse-smtp-template": "^2.2.0", it works well on "template: true",but failed on "multiTemplate: true"

here is my configure:
emailAdapter: {
module: 'parse-smtp-template',
options: {
secure: true,
port: 465,
host: "xxxxxx",
user: "xxxxxx",
password: "xxxxxx",
fromAddress: 'xxxxxxx',

        //template: true,
        //templatePath: "templates/main.html",
        multiTemplate: true,
        confirmTemplatePath: "templates/confirmTemplate.html",
        //passwordTemplatePath: "templates/passwordTemplate.html",
        passwordTemplatePath: "templates/main.html",

        passwordOptions: {
            subject: "Password reset",
            body: "password recovery email",
            btn: "Reset Password",
            others: {
              test:"test"
            }
        },
        confirmOptions: {
            subject: "verify email",
            body: "email confirmation",
            btn: "Confirm Email"
        },
    }
},

it report errors after request email:

{"level":"error","message":"Uncaught internal server error. username is not defined","stack":"ReferenceError: username is not defined\n at eval (eval at sendPasswordResetEmail (/root/www/node_modules/parse-smtp-template/index.js:292:24), :264:60)\n at Object.sendPasswordResetEmail (/root/www/node_modules/parse-smtp-template/index.js:292:24)\n at UserController.sendPasswordResetEmail (/root/www/node_modules/parse-server/lib/Controllers/UserController.js:295:20)\n at processTicksAndRejections (internal/process/task_queues.js:95:5)","timestamp":"2021-09-02T04:52:21.810Z"}

Any way to set "From" name

Is there anyway to set the from name using this module? I mean, say I set the mail to be sent from '[email protected]'. Currently name shows as 'no-reply' (refer attached pic
name
). Any way to make this show as 'My Company'?

error when trying to reset password

m getting this issue when i try to send mails with port 465 through gmail and secure : true

 [Error: 139953853953920:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:332:
0|Dwaya  | ] {
0|Dwaya  |   library: 'SSL routines',
0|Dwaya  |   function: 'ssl3_get_record',
0|Dwaya  |   reason: 'wrong version number',
0|Dwaya  |   code: 'ESOCKET',
0|Dwaya  |   command: 'CONN'
0|Dwaya  | }

"others" parameter not working with multiLang

Even if you set extra parameters for every language the module continues to load default ones and not those of the right language.
I read the code and in fact only "others" parameters from "confirmOptions" and "passwordOptions" are loaded; for langOptions only "subject", "body" and "btn" parameters are loaded.

Error: Greeting never received

Hello I am trying to use template with below specs :

emailAdapter: {
    module: 'parse-smtp-template',
    options: {
      port: 465,
      host: "mail.playm.io",
      user: "[email protected]",
      password: "***********",
      fromAddress: '[email protected]'
    }
  }

But it gives this error

(node:4423) UnhandledPromiseRejectionWarning: Error: Greeting never received
at SMTPConnection._formatError (/Users/suatkarabacak/Desktop/playm/node_modules/parse-smtp-template/node_modules/nodemailer/lib/smtp-connection/index.js:784:19)
at SMTPConnection._onError (/Users/suatkarabacak/Desktop/playm/node_modules/parse-smtp-template/node_modules/nodemailer/lib/smtp-connection/index.js:770:20)

Adding Extra Parameters not working

Hello,
I am trying to add some extra parameters to my config file and template but it is not working out fine.
"multiLangConfirm": {

  "en": {
    "subject": "E-mail confirmation",
    "body": "Mail confirmation email body",
    "btn": "confirm your email",
    "others": {
      "footer": "Thank you!"
    }
    
  },

In the HTML template confirmTemplate.html I am adding ${others.footer}
Please let me know if this works or the correct way that it works with.

Thanks

Support 'default' language

When a user has the 'multiLangColumn' property set to a value that is not in the list (in multiLangPass for example), we get a 500 error.

Example:

For:
user.get('lang') = 'es'

multiLangPass: {
en: {
subject: "Password Reset",
body: "Somebody (hopefully you) requested a new password.",
btn: "Reset your password"
},
fr: {
subject: "Réinitialiser votre mot de passe",
body: "Quelqu'un a demandé un nouveau mot de passe pour votre compte.",
btn: "Réinitialiser votre mot de passe"
}
},

This throws a 500.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.