Skip to content

xander-email is a library to facilitate the use of nodemailer

License

Notifications You must be signed in to change notification settings

ZaikoXander/xander-email

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

xander-email

A library to facilitate the use of nodemailer.

npm GitHub

Installation

You may install this module using npm or Yarn.

npm i xander-email

Or yarn add xander-email for Yarn

How to use

import xanderEmail from "xander-email"

transport.sendMail({
  from: "Support <support@gmail.com>",
  to: "Client <client@gmail.com>",
  subject: "Test",
  html: xanderEmail("view1", "./src/modules/mailer/views", { title: "xander-email" }) 
})

Views

Assuming that you already know how to use nodemailer, start creating a folder for the email's views.
This views is basically web pages (html), so you just need to create elements like this:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div style="background-color: black; height: 100vh;">
    {{title}}
    {{greenBox}}
  </div>
</body>
</html>

Components

You probably notice that this two lines are not html elements.
So... What is it?

{{title}}
{{greenBox}}

Well, those are components, which can be called from multiple different Views.
And in reality to take an example, here we have the title component:

<h1 style="color: white; font-family: Arial, Helvetica, sans-serif;">
  {{-title}}
</h1>

Variables

There are variables too, we will take a look how to use them later.

{{-title}}

Finally getting our views using xander-email

Before, you need to make sure that the components folder is inside the views folder. Just like this: folder_example
And the name of the components folder needs to be in lowercase (for now).

Now we just need to create the transport of nodemailer, and when sending the Email, write on the html param something like:

import xanderEmail from "xander-email"

transport.sendMail({
  from: "Support <support@gmail.com>",
  to: "Client <client@gmail.com>",
  subject: "Test",
  html: xanderEmail("body", "./src/modules/mailer/views", { title: "xander-email" }) // <--
})

Params

  • viewName(the name of the view file that you want)
  • viewsPath(the path to your views folder, and it includes the view folder itself)
  • variables(an object that receives keys (name of the variables of the views) and the values of it)