0.4.79 • Published 9 days ago

larvitammail v0.4.79

Weekly downloads
1
License
UNLICENSED
Repository
github
Last release
9 days ago

Build Status

larvitammail

Mailing framework for the Larvit AM project

Subscribing to exchanges in the RabbitMQ-network and by extensions and templates sends emails depending on rules in the extensions.

Usage

Setup

const Intercom = require('larvitamintercom'),
const AmMail = require('larvitammail'),
const Mail = require('larvitmail');

const amMail = new AmMail({
	intercom: new Intercom('amqp://user:password@192.168.0.1/'), // It is important this is a standalone intercom instance!
	mail: new Mail({
		transportConf: 'smtps://user%40gmail.com:pass@smtp.gmail.com',
		mailDefaults: {
			from: 'foo@bar.com'
		}
	}),
});

await amMail.registerSubscriptions();
// Up and running now!

Subscriptions

Now create a folder in your process.cwd() called "subscriptions". In that directory you create another folder with the same name as your exchange in you subscriptions, in this case "exampleExchange". Now create a file in that directory with the same as your action in that exchange, in this case "exampleAction.js"

And it should look something like this (subscriptions/exampleExchange/exampleAction.js):

// The value "params" here is the object that was sent in the subscriptions message.
exports = module.exports = async params => {
	return {
		// Mandatory
		to: 'bar@foo.com',

		// Optional
		subject: 'The file you wanted', // Defaults to empty string
		from: 'from@someone.com', // Defaults to mail defaults from
		templateData: {'username': 'Lennart'}, // Defaults to empty object. This is the data that will be sent to the email template.
		notSend: true, // Will make this email not being sent
		template: 'subscriptions/exampleExchange/exampleAction.tmpl',	// Defaults to the same as this file, but tmpl instead of js as file ending

		// Attachments, attached files, optional
		attachments: [
			{
				filename: 'text.txt',
				content: new Buffer('hello world!', 'utf-8')
			}
		]
	};
};

Templates

As default to our above subscription, create a file in process.cwd(): subscriptions/exampleExchange/exampleAction.tmpl

The templating is done with lodash and it should look something like this:

Hi <%= obj.username %>!
Here is the file you requested.

Best regards
Mr. Smith

Result

Now will larvitammail listen to the exchange "exampleExchange" and as soon a message with the action "exampleAction" is received the mailer will look for the subscription in "subscriptions/exampleExchane/exampleAction.js" and will return data to proceed. Then it will fetch the template in "subscriptions/exampleExchane/exampleAction.tmpl" and send the email.

0.4.79

9 days ago

0.4.78

16 days ago

0.4.77

23 days ago

0.4.76

1 month ago

0.4.75

1 month ago

0.4.74

2 months ago

0.4.73

2 months ago

0.4.72

2 months ago

0.4.71

3 months ago

0.4.70

3 months ago

0.4.69

3 months ago

0.4.68

4 months ago

0.4.67

4 months ago

0.4.66

4 months ago

0.4.65

4 months ago

0.4.64

5 months ago

0.4.63

5 months ago

0.4.62

6 months ago

0.4.61

6 months ago

0.4.60

7 months ago

0.4.53

8 months ago

0.4.54

8 months ago

0.4.52

8 months ago

0.4.59

7 months ago

0.4.57

7 months ago

0.4.58

7 months ago

0.4.55

8 months ago

0.4.56

7 months ago

0.4.51

9 months ago

0.4.42

1 year ago

0.4.43

12 months ago

0.4.48

11 months ago

0.4.49

11 months ago

0.4.46

11 months ago

0.4.47

11 months ago

0.4.44

12 months ago

0.4.45

11 months ago

0.4.50

10 months ago

0.4.40

1 year ago

0.4.41

1 year ago

0.4.39

1 year ago

0.4.38

1 year ago

0.4.31

1 year ago

0.4.32

1 year ago

0.4.30

1 year ago

0.4.37

1 year ago

0.4.35

1 year ago

0.4.36

1 year ago

0.4.33

1 year ago

0.4.34

1 year ago

0.4.20

2 years ago

0.4.21

2 years ago

0.4.28

1 year ago

0.4.29

1 year ago

0.4.26

1 year ago

0.4.27

1 year ago

0.4.24

1 year ago

0.4.25

1 year ago

0.4.22

2 years ago

0.4.23

1 year ago

0.4.19

2 years ago

0.4.17

2 years ago

0.4.18

2 years ago

0.4.15

2 years ago

0.4.16

2 years ago

0.4.14

2 years ago

0.4.10

2 years ago

0.4.9

2 years ago

0.4.8

2 years ago

0.4.13

2 years ago

0.4.11

2 years ago

0.4.12

2 years ago

0.4.5

2 years ago

0.4.4

2 years ago

0.4.7

2 years ago

0.4.6

2 years ago

0.4.3

2 years ago

0.4.2

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.3.0

4 years ago

0.2.1

4 years ago

0.2.0

5 years ago

0.1.1

7 years ago