pmail 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in pmail.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,20 @@
1
+ pmail
2
+ =====
3
+
4
+ pmail, send mail using [Postmark](http://postmarkapp.com/) from the command line.
5
+
6
+ Usage
7
+ -----
8
+
9
+ pmail will look for a YAML file located in ~/.pmail which can be used to specify any of the parameters that pmail takes.
10
+
11
+ This is most useful for specifying your Postmark API key and sender signature. For example:
12
+
13
+ ---
14
+ :api_key: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
15
+ :from: Ben Ubois <ben@benubois.com>
16
+
17
+ Examples
18
+ --------
19
+
20
+ $ pmail -t ben@benubois.com -s Subject < message_body.txt
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/pmail ADDED
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pmail'
3
+ require 'optparse'
4
+ require 'fcntl'
5
+
6
+ config = Pmail::Config.new
7
+
8
+ options = {
9
+ :body => (STDIN.fcntl(Fcntl::F_GETFL, 0) == 0) ? STDIN.read : '',
10
+ :format => :plain
11
+ }
12
+
13
+ optparse = OptionParser.new do |opts|
14
+
15
+ opts.on( '-f', '--from from', "From address. Must be a valid Postmark signature." ) do |arg|
16
+ options[:from] = arg
17
+ end
18
+
19
+ opts.on( '-t', '--to a,b,c', Array, "To address. For multiple, use comma separated addresses." ) do |arg|
20
+ options[:to] = arg
21
+ end
22
+
23
+ opts.on( '-s', '--subject subject', "The emails subject." ) do |arg|
24
+ options[:subject] = arg
25
+ end
26
+
27
+ opts.on( '-k', '--key api_key', "Your Postmark API key." ) do |arg|
28
+ options[:api_key]
29
+ end
30
+
31
+ opts.on('--format format', [:plain, :html], "Mail message format." ) do |arg|
32
+ options[:format] = arg.to_s
33
+ end
34
+
35
+ opts.on('-h', '--help', 'Display help info') do
36
+ puts opts
37
+ exit
38
+ end
39
+ end
40
+
41
+ begin
42
+ optparse.parse!
43
+ options = config.settings.merge(options)
44
+ mandatory = [:from, :to, :body, :api_key]
45
+ missing = mandatory.select{ |param| options[param].nil? }
46
+ if not missing.empty?
47
+ puts "Missing options: #{missing.join(', ')}"
48
+ puts optparse
49
+ exit
50
+ end
51
+ rescue OptionParser::InvalidOption, OptionParser::MissingArgument
52
+ puts $!.to_s
53
+ puts optparse
54
+ exit
55
+ end
56
+
57
+ begin
58
+ message = Pmail::Message.new(options)
59
+ message.send
60
+ rescue Postmark::InvalidMessageError
61
+ puts "Invalid message: " + $!.to_s
62
+ exit 1
63
+ rescue Exception => e
64
+ puts e.to_s
65
+ exit 1
66
+ end
data/lib/pmail.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "pmail/version"
2
+ require "pmail/config"
3
+ require "pmail/message"
4
+
5
+ module Pmail
6
+
7
+ end
@@ -0,0 +1,22 @@
1
+ require 'fileutils'
2
+ module Pmail
3
+
4
+ class Config
5
+
6
+ include FileUtils
7
+
8
+ FILE = "#{ENV['HOME']}/.pmail"
9
+
10
+ attr_reader :settings
11
+
12
+ def initialize
13
+ @settings = read_settings
14
+ end
15
+
16
+ def read_settings
17
+ File.exist?(FILE) ? YAML.load_file(FILE) : {}
18
+ end
19
+
20
+ end
21
+
22
+ end
@@ -0,0 +1,46 @@
1
+ require 'postmark'
2
+ require 'mail'
3
+ require 'yaml'
4
+
5
+ module Pmail
6
+ class Message
7
+
8
+ def initialize(options = {})
9
+ @from = options[:from]
10
+ @to = options[:to]
11
+ @subject = options[:subject]
12
+ @body = options[:body]
13
+ @api_key = options[:api_key]
14
+ @format = options[:format]
15
+ end
16
+
17
+ def send
18
+
19
+ message = Mail.new
20
+ message.delivery_method(Mail::Postmark, :api_key => @api_key)
21
+
22
+ message.from = @from
23
+ message.to = @to
24
+ message.subject = @subject
25
+ message.body = @body
26
+
27
+ # TODO make this user configurable
28
+ message.content_type = "text/#{@format}"
29
+
30
+ # TODO add custom header support
31
+ # message["CUSTOM-HEADER"] = "header"
32
+
33
+ # TODO add tag support
34
+ # message.tag = "tag"
35
+
36
+ # TODO add attachment support
37
+ # message.postmark_attachments = [File.open("/path")]
38
+
39
+ # TODO add reply-to support
40
+ # message.reply_to = "reply to"
41
+
42
+ message.deliver
43
+ end
44
+
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ module Pmail
2
+ VERSION = "0.0.2"
3
+ end
data/pmail.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "pmail/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "pmail"
7
+ s.version = Pmail::VERSION
8
+ s.authors = ["Ben Ubois"]
9
+ s.email = ["ben@benubois.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Command-line Postmark}
12
+ s.description = %q{Send mail using the Postmark API from the command line.}
13
+
14
+ s.rubyforge_project = "pmail"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency "postmark"
22
+ s.add_dependency "mail"
23
+ s.add_dependency "json"
24
+
25
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pmail
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - Ben Ubois
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-08-28 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: postmark
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: mail
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: json
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :runtime
62
+ version_requirements: *id003
63
+ description: Send mail using the Postmark API from the command line.
64
+ email:
65
+ - ben@benubois.com
66
+ executables:
67
+ - pmail
68
+ extensions: []
69
+
70
+ extra_rdoc_files: []
71
+
72
+ files:
73
+ - .gitignore
74
+ - Gemfile
75
+ - README.md
76
+ - Rakefile
77
+ - bin/pmail
78
+ - lib/pmail.rb
79
+ - lib/pmail/config.rb
80
+ - lib/pmail/message.rb
81
+ - lib/pmail/version.rb
82
+ - pmail.gemspec
83
+ has_rdoc: true
84
+ homepage: ""
85
+ licenses: []
86
+
87
+ post_install_message:
88
+ rdoc_options: []
89
+
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ hash: 3
98
+ segments:
99
+ - 0
100
+ version: "0"
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ hash: 3
107
+ segments:
108
+ - 0
109
+ version: "0"
110
+ requirements: []
111
+
112
+ rubyforge_project: pmail
113
+ rubygems_version: 1.6.2
114
+ signing_key:
115
+ specification_version: 3
116
+ summary: Command-line Postmark
117
+ test_files: []
118
+