https://github.com/betaweb/mailr
Fluent mail library for NodeJS
https://github.com/betaweb/mailr
email email-sender fluent nodejs
Last synced: about 2 months ago
JSON representation
Fluent mail library for NodeJS
- Host: GitHub
- URL: https://github.com/betaweb/mailr
- Owner: betaWeb
- Created: 2017-10-12T15:44:58.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-03-11T11:37:17.000Z (almost 8 years ago)
- Last Synced: 2025-03-09T13:35:05.362Z (11 months ago)
- Topics: email, email-sender, fluent, nodejs
- Language: JavaScript
- Size: 1.39 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Mailr
## A fluent mail library for NodeJS based on [Nodemailer](https://github.com/nodemailer/nodemailer)
The goal of Mailr is simple : create and send emails by fluent-way with NodeJS.
### Basic example :
#### NodeJS :
```javascript
const Mailr = require('Mailr')
// Example with Gmail SMTP service
const mailr = new Mailr({
transporter_options: {
service: 'gmail',
port: 465,
secure: true,
host: 'smtp.gmail.com',
auth: {
user: 'email.address@gmail.com', // Here your Gmail address
pass: 'mysecurepassword' // Here your Gmail password
}
}
})
mailr
.createMessage()
.from('no-reply@local.dev')
.to('receiver@domain.com')
.subject('Mailr is awesome !')
.template('my_awesome_template.njk')
.params({
title: 'Mail sended with Mailr',
content: 'This email has been sended with Mailr lib, and it "roxx du poney" !'
})
.send()
.then(_ => console.log('Email sended'))
.catch(console.error)
```
#### Template (with [Nunjucks](https://mozilla.github.io/nunjucks/) by default) :
```HTML
{{ title }}
{{ content }}
```
### Example with attachment :
#### NodeJS :
```javascript
const options = {
mailer: {
template_path: './templates',
transporter_options: {
service: 'gmail',
port: 465,
secure: true,
host: 'smtp.gmail.com',
auth: {
user: 'email.address@gmail.com', // Here your Gmail address
pass: 'mysecurepassword' // Here your Gmail password
}
}
},
message: {
default_from: 'No-reply '
}
}
const email = new Mailr(options).createMessage()
const message = email
.template('tpl_name')
.to('contact@local.dev')
.subject('My awesome email with attachment')
.attachment(
'path/to/attachment.pdf', // Path to attachment file
'My PDF file', // Attachment name
{ contentType: 'application/pdf' } // Attachment options
)
.params({
title: 'This PDF file rocks !',
content: 'Look at this awesome attachment dude !'
})
message.send()
.then(_ => console.log('Email sended with attachment'))
.catch(console.error)
```