npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mail-wizard

v3.0.1

Published

allows you to send e-mails (text / template) to your website users

Downloads

8

Readme

#mail-wizard v 3.0.1 ##Discription You can use this package for your app to send mails ( text / templates) to your users simply . ####Notes

  • you may need to make your mailing service (Gmail , Yahoo ,...) accepting low security apps , follow this link https://goo.gl/bKzfOP. ##install
$npm install mail-wizard --save

##How to use

  • first into your project directory , create a folder called json , and json file called data.json into that folder .
yourApp/
----json
-------data.json
----templates
-------welcome.hjs
-------verification.hjs
-------forgetpassword.hjs
----index.js
----packages.json

into your data.json file put empty curly brackets {}

###functions

####1.set & update enables you to set a list of data that will be save into a file in order not to load them each time you want to send an email .


Arguments it takes an object that have the data of the mailing operation like (mail , password , subject , text , ....etc ) it must be if the form of this object .

var  data = {
 key : "forgetPassword" ,
 mail : "[email protected]" ,
 password : "*******"
 subject : "Post man" ,
 text : " Hello " ,
 template : "<h1>welcome {{name}}</h1>",
 variables : ["name"]
 };

If you don't want to use any of the last three properties leave them blank , but they must be included into your object.


Arguments Discription :

  • key ::: it's a name for your mailing operation like ( verification , forget password , broadcast ... etc ) .So when you want to send mail you can just mention your operation key .
  • mail & password ::: the mail and passwrod you want to send from this kind of mails .
  • subject ::: subject of you emails of this operation
  • text ::: body of you email
  • template ::: its an email template(html file) but you must get it into string use (fs package) .. if your mail have some variables like the name of the user you send the mail to you then use (hjs package).
  • variables ::: it's an array have the variables your template has

Example :

var mail-wizard = require('mail-wizard');

var data = {
key : "verification" ,
mail : "[email protected]" ,
password : "********" ,
subject : "Email verification " ,
text : "hello" ,
template : "" ,
variables : []
}

mail-wizard.set(data) ;

You can update function to update the date you have set . by sending the key of the data you want to update and object with new or updated data .

Example

 var mail-wizard = require('mail-wizard');
 
 var data = {
 key : "verification" ,
 mail : "[email protected]",
 password:"########",
 name : "mahmoud"
 };
 
 mail-wizard.update(data) ;

####2.send

With this function you can send mails for one user

Arguments : this function takes two argument ( key , user )

  • key ::: its the key of operation that you have set before with your data
  • user ::: it's an object that have user data , make sure that this object have all data you may use . if you specfied some variables into your template this object must have this information even if they are empty .

Example :

 var mail-wizard = require("mail-wizard") ;
 
 var user = {
 mail : "[email protected]" ,
 name : "Haleem" ,
 mobile : "" 
 };
 
 mail-wizard.send("verification" , user );

If you want send a particular email (special text for a user ) you can use sendParticular function .


####3.sendParticular With this function you can text a user with particular email .


Example:

var mail-wizard = require("mail-wizard");

var data = {
form : "[email protected]",
password : "********",
to : "[email protected]",
subject : "Particular Email" ,
text : "Hello mr.Haleem ............." ,
template : ""
};

mail-wizard.sendParticular(data);

####4.sendToAll With this function you can send an email to all your users with only one line of code .


Arguments: it takes two arguments ( key , users)

  • key ::: its the type of operation we have set before
  • users ::: it's array of object each object have the userss data you need ( mail , and any other information you have set as variable into your template if you want to use template )

Example :

var mail-wizard = require('mail-wizard') ;

 //this data ( broadcast as example ) you can set one time and use this kind of mailing with one the key , you don't have to set these data every time 
 
 var broadcast = {
 key : "broadcast" ,
 mail : "[email protected]" ,
 password : "*******" ,
 subject : "new promotions for you" ,
 text : "hey all " ,
 template : "",
 variables : [] 
 }
 
 var users = [
 {
 mail : "[email protected]" 
 },
 {
 mail : "[email protected]"
 }
 ];
 
 mail-wizard.sendToAll("broadcast" , users) ;

###using Templates

in this example i will use a template of welcome msg to your new users .. and use the broadcast key after upating the template property .

welcom.hjs

<!doctype html>
 <html>
  <head>
  <style>
  h1 {
  color : red ;
  }
  </style>
  </head>
  <body>
  <h1> Welcome {{name}} </h1>
  </body>
  </html>

index.js

var mail-wizard = require("mail-wizard") ;
 var fs = require("fs") ;
 
 ///search for the diffrenet between readFile and readFileSync
 
 var template = fs.readFileSync('./templates/welcome.hjs', 'utf-8' ) ;
 
 var data = {
 template : template ,
 variables : ["name"]
 };
 
 /// you can fetch this data from your database and just put it in array of objects 
 var users = [
{ 
mail : "[email protected]" ,
name : "user1" ///make sure that this property has the same name as the variable you set
} ,
{
mail : "[email protected]" ,
name : "user2"
}];

 mail-wizard.update("broadcast" , data);
 mailman.sendToAll("broadcast" , users) ;