1.2.8 • Published 5 years ago

mail-promise v1.2.8

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

mail-promise

Simplifies the interface for nodemailer and returns a promise. Also includes TypeScript declaration file for type checking. Credentials for the email service can be passed in the MailPromise class constructor or through the environment variables. Setting the credentials from the environment variables is useful for when you want to use mail credentials in multiple projects but not risk having them exposed.

To set the credentials from the environment variables you need to create one for the service, the username, and the password. The file you edit will vary depending on your system. I set mine on Linux from /etc/environment.

The three variables are:

  • MAILPROMISESERVICE="your service" // i.e. Gmail
  • MAILPROMISEUSER="email/username" // i.e. seanmaxwell@gmail.com
  • MAILPROMISEPWD="password" // i.e. Password@1

If you pass the variables from the constructor, MailPromise will use those instead. If you leave an entry blank in the constructor, MailPromise will try to pull the environment variables.

created by Sean Maxwell June 25, 2018

  • TypeScript example:
import MailPromise from 'mail-promise';


class SomeClass {
    
    private readonly _mailer: MailPromise;                
                    
    constructor() {
        this._mailer = new MailPromise('Gmail', 'example@gmail.com', 'Password@1');
        // or this._mailer = new MailPromise(); // if using environment variables
    }
    
    async sendMail(to: string, from: string, subject: string, body: string, html?: string, 
                   attachments?: Array<any>): Promise<void> {
        
        try {
            // html and attachments params are optional
            let info = await this._mailer.send(to, from, subject, body, html, attachments); 
            console.log(info.response);
        } catch (err) {
            console.error(err);
        }
    }
}
var MailPromise = require('mail-promise').default;

var mailer = new MailPromise('Gmail', 'example@gmail.com', 'Password@1'); 


mailer.send(to, from, subject, body, html)
        .then(info => {
            console.log(info.response);
        })
        .catch(err => {
            console.error(err);
        })
1.2.8

5 years ago

1.2.7

5 years ago

1.2.6

5 years ago

1.2.5

5 years ago

1.2.4

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.6

5 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago