# mail-wizard

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

Latest version **3.0.1** (published 2016-08-22) · ISC license · 0 weekly downloads

## Install

```sh
npm install mail-wizard
pnpm add mail-wizard
yarn add mail-wizard
bun add mail-wizard
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.1 |
| Published | 2016-08-22 |
| First published | 2016-08-22 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Known vulnerabilities | 0 (+16 in 2 direct dependencies) |
| Install scripts | no |
| Author | Haleem |
| Maintainers | haleem |
| Keywords | mail, send mails, templates, nodemailer |

## Links

- npm: https://www.npmjs.com/package/mail-wizard
- npm.io page: https://npm.io/package/mail-wizard

## Dependencies (5)

- [fs](https://npm.io/package/fs.md) 0.0.2
- [hjs](https://npm.io/package/hjs.md) 0.0.6
- [express](https://npm.io/package/express.md) ^4.6.1
- [hogan.js](https://npm.io/package/hogan.js.md) ^3.0.2
- [nodemailer](https://npm.io/package/nodemailer.md) ^0.7.1

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 3.0.1 (latest) — 2016-08-22
- 3.0.0 — 2016-08-22
- 1.1.0 — 2016-08-22
- 2.0.2 — 2016-08-22
- 2.0.1 — 2016-08-22

## 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 : "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) ;
```
 
----------

---
_Source: https://npm.io/package/mail-wizard · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
