3.0.1 • Published 8 years ago

mail-wizard v3.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
8 years ago

#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 : "haleem@postman.com" ,
 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 : "mahmoud.haleem112@gmail.com" ,
    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 : "mhaleem@icloud.com",
 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 : "m7mod_7leem@yahoo.com" ,
 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 : "mahmoud.haleem112@gmail.com",
password : "********",
to : "m7mod_7leem@yahoo.com",
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 : "mahmoud.haleem112@gmail.com" ,
 password : "*******" ,
 subject : "new promotions for you" ,
 text : "hey all " ,
 template : "",
 variables : [] 
 }
 
 var users = [
 {
 mail : "m7mod_7leem@yahoo.com" 
 },
 {
 mail : "mahmoud.haleem112@gmail.com"
 }
 ];
 
 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 : "user1@gmail.com" ,
name : "user1" ///make sure that this property has the same name as the variable you set
} ,
{
mail : "user2@icloud.com" ,
name : "user2"
}];

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

3.0.1

8 years ago

3.0.0

8 years ago

1.1.0

8 years ago

2.0.2

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago