Permalink
Browse files

init

  • Loading branch information...
0 parents commit 4d409c291b5ab7558e022d8e72a03a61c390f988 @vadimdemedes committed Jul 2, 2012
Showing with 176 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +45 −0 Readme.md
  3. +1 −0 index.js
  4. +29 −0 lib/mailman.coffee
  5. +58 −0 lib/mailman.js
  6. +17 −0 package.json
  7. +24 −0 test/mailman.test.coffee
  8. +1 −0 test/mocha.opts
@@ -0,0 +1 @@
+node_modules
@@ -0,0 +1,45 @@
+# Mailman
+
+Send emails in a comfortable way via models.
+
+# Installation
+
+`npm install mailman`
+
+# Usage
+
+## Connecting
+
+```coffee-script
+Mailman = require 'mailman'
+
+Mailman.connect service: 'smtp', host: 'smtp.gmail.com', user: 'test@gmail.com', password: 'test', ssl: yes
+```
+
+## Defining
+
+```coffee-script
+class Notifier extends Mailman.Model
+ from: 'support@newapp.com'
+ subject: 'NewApp launched!'
+ text: 'Yes yes yes, you heard it.'
+
+Notifier = Mailman.setup Notifier # this is required
+```
+
+## Sending
+
+```coffee-script
+mail = new Notifier
+mail.to = 'recipient@gmail.com'
+mail.deliver (err, response) ->
+ # email sent
+```
+
+# Tests
+
+Put in your auth credentials into **test/mailman.test.coffee** and run `mocha` in Terminal.
+
+# License
+
+MIT.
@@ -0,0 +1 @@
+module.exports = require('./lib/mailman');
@@ -0,0 +1,29 @@
+Mailer = require 'nodemailer'
+
+class Mailman
+ @connect: (params) ->
+ transport = if params.service.toLowerCase() is 'ses' then 'SES' else 'SMTP'
+ params.auth = user: params.user, pass: params.password
+ params.secureConnection = !! params.ssl
+ @transport = Mailer.createTransport transport, params
+
+ @setup: (model) ->
+ model::transport = @transport
+ model
+
+class Mailman.Model
+ constructor: ->
+ @attachments = []
+ @generateTextFromHTML = yes
+
+ deliver: (callback) ->
+ keys = ['from', 'to', 'cc', 'bcc', 'replyTo', 'subject', 'text', 'html', 'headers', 'attachments', 'encoding']
+ params = {}
+ for key in keys
+ params[key] = @[key] if @[key] and @[key].length > 0
+
+ @transport.sendMail params, callback
+
+ send: -> @deliver.apply @, arguments
+
+module.exports = Mailman
Oops, something went wrong.
@@ -0,0 +1,17 @@
+{
+ "name": "mailman",
+ "description": "Send emails in a comfortable way via models.",
+ "version": "0.1.0",
+ "author": "Vadim Demedes <sbioko@gmail.com>",
+ "license": "MIT",
+ "index": "./index.js",
+ "engine": {
+ "node": ">= 0.4"
+ },
+ "dependencies": {
+ "nodemailer": "latest"
+ },
+ "devDependencies": {
+ "should": "latest"
+ }
+}
@@ -0,0 +1,24 @@
+Mailman = require '../'
+
+should = require 'should'
+
+describe 'Mailman', ->
+ describe 'Transports', ->
+ describe 'SMTP', ->
+ it 'should send out an email', (done) ->
+ Mailman.connect host: 'smtp.sendgrid.net', service: 'smtp', port: 587, user: 'user', password: 'password'
+
+
+ class Notifier extends Mailman.Model
+ from: 'test@test.com'
+ subject: 'We launched!'
+ text: 'We launched, sign up right now!'
+
+ Notifier = Mailman.setup Notifier
+
+ mail = new Notifier
+ mail.to = 'test@test2.com'
+ mail.deliver (err, response) ->
+ should.not.exist err
+ done()
+
@@ -0,0 +1 @@
+--compilers coffee:coffee-script --timeout 20000

0 comments on commit 4d409c2

Please sign in to comment.