Code Monkey home page Code Monkey logo

xander-email's Introduction

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 <[email protected]>",
  to: "Client <[email protected]>",
  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 <[email protected]>",
  to: "Client <[email protected]>",
  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)

xander-email's People

Contributors

zaikoxander avatar

Watchers

 avatar

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.