notes_mailer 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc ADDED
@@ -0,0 +1,8 @@
1
+ == Version 0.0.1 - 2010-11-06 <goesser3@gmail.com>
2
+ * initial public release
3
+
4
+ == Version 0.0.0 - 2010-10-27 <goesser3@gmail.com>
5
+ * attaching files via add_file
6
+
7
+ == Version 0.0.0 - 2010-06-18 <goesser3@gmail.com>
8
+ * initial release
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009, 2010 Elias Kugler
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,65 @@
1
+ = NotesMailer
2
+
3
+ Small gem that uses IBM Lotus Notes to deliver your e-mails.
4
+
5
+ == Installation
6
+
7
+ # gem install notes_mailer
8
+
9
+ == Usage
10
+ require 'rubygems'
11
+ require 'notes_mailer'
12
+
13
+ Mail.defaults do
14
+ delivery_method Mail::NotesMailer, {
15
+ :address => "", # your Notes-Server adress
16
+ # "" or default if you are using a local database
17
+ :user_name => '<username>',
18
+ :password => '<password>',
19
+ :db => '<database>'}
20
+ end
21
+
22
+ Mail.deliver do
23
+ to 'mikel@test.lindsaar.net'
24
+ subject 'testing notes_mailer'
25
+ body 'testing notes_mailer'
26
+ add_file 'c:/path/to/file.txt'
27
+ end
28
+
29
+ == Prerequisites
30
+
31
+ 1. Ruby 1.8.6 or later
32
+ 2. IBM Lotus Notes
33
+
34
+ == Supported Platforms
35
+
36
+ This library is supported on Windows 2000 or later.
37
+
38
+ ==Used libs:
39
+ * win32ole
40
+ * mail
41
+ * log4r
42
+ ...
43
+
44
+ == Licence/Copyright
45
+
46
+ Copyright (c) 2010 Elias Kugler
47
+
48
+ Permission is hereby granted, free of charge, to any person obtaining
49
+ a copy of this software and associated documentation files (the
50
+ "Software"), to deal in the Software without restriction, including
51
+ without limitation the rights to use, copy, modify, merge, publish,
52
+ distribute, sublicense, and/or sell copies of the Software, and to
53
+ permit persons to whom the Software is furnished to do so, subject to
54
+ the following conditions:
55
+
56
+ The above copyright notice and this permission notice shall be
57
+ included in all copies or substantial portions of the Software.
58
+
59
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
60
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
61
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
62
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
63
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
64
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
65
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,189 @@
1
+ require 'mail'
2
+ require 'fileutils'
3
+ require 'log4r'
4
+
5
+ module Mail
6
+
7
+ # == Sending Email with NotesMailer
8
+ #
9
+ # NotesMailer allows you to send emails using IBM Lotus Notes. This is done by wrapping the Lotus Notes-win32ole-api.
10
+ # The usage is very similar to the SMTP devlivery method in the mail gem.
11
+ #
12
+ # require 'rubygems'
13
+ # require 'notes_mailer'
14
+ #
15
+ # Mail.defaults do
16
+ # delivery_method Mail::NotesMailer, { :address => "",
17
+ # :user_name => '<username>',
18
+ # :password => '<password>',
19
+ # :db => '<database>'}
20
+ # end
21
+ #
22
+ # === Delivering the email (from smtp.rb)
23
+ #
24
+ # Once you have the settings right, sending the email is done by:
25
+ #
26
+ # Mail.deliver do
27
+ # to 'mikel@test.lindsaar.net'
28
+ # from 'ada@test.lindsaar.net'
29
+ # subject 'testing sendmail'
30
+ # body 'testing sendmail'
31
+ # end
32
+ #
33
+ # Or by calling deliver on a Mail message
34
+ #
35
+ # mail = Mail.new do
36
+ # to 'mikel@test.lindsaar.net'
37
+ # from 'ada@test.lindsaar.net'
38
+ # subject 'testing sendmail'
39
+ # body 'testing sendmail'
40
+ # end
41
+ #
42
+ # mail.deliver!
43
+ class Message
44
+ alias old_initialize initialize
45
+ attr_reader :files_to_attach
46
+ def initialize(*args, &block)
47
+ @files_to_attach = []
48
+ old_initialize(*args, &block)
49
+ end
50
+ def add_file(filename)
51
+ raise "Parameter must be a string" unless filename.is_a?String
52
+ raise "File '#{filename}' does not exists" unless File.exists?(filename)
53
+ @files_to_attach << filename
54
+ end
55
+ end
56
+
57
+ class NotesMailer
58
+ @@logger = nil
59
+ # Provides a store of all the emails
60
+ def NotesMailer.deliveries
61
+ @@deliveries ||= []
62
+ end
63
+
64
+ def NotesMailer.deliveries=(val)
65
+ @@deliveries = val
66
+ end
67
+
68
+ # NotesMailer supports the following settings:
69
+ # Mandatory:
70
+ # :user_name ... Lotus Notes user
71
+ # :db ... Latus Notes database
72
+ # Optional
73
+ # :password ... Latus Notes password
74
+ # :adress ... Adress of your Lotus Notes Server, emty if you are using a local database
75
+ # ::mock_win32ole => true ... test without using Lotus Notes
76
+ # :logger => true, ... use logger
77
+ # :debug => true ...
78
+ def initialize(values)
79
+ self.settings = { :adress => '', #server is localhost
80
+ :password => ''
81
+ }.merge(values)
82
+
83
+
84
+ #raise "Notes password missing" unless settings[:password]
85
+ raise "Notes db missing" unless settings[:db]
86
+ raise "Notes user_name missing" unless settings[:user_name]
87
+
88
+ if settings[:mock_win32ole]
89
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../test/mock/win32ole'
90
+ end
91
+ require 'win32ole'
92
+
93
+ if settings[:logger] and !@@logger
94
+ NotesMailer.init_logger(settings[:debug])
95
+ end
96
+
97
+ log_debug "--- settings --- "
98
+ log_debug settings
99
+
100
+ s = WIN32OLE.new 'Lotus.NotesSession'
101
+ s.Initialize(settings[:password])
102
+
103
+ @notes_db = s.GetDatabase(settings[:adress], settings[:db])
104
+ raise "Cannot open #{settings[:db]}" unless @notes_db.IsOpen()
105
+
106
+ end
107
+
108
+ attr_accessor :settings
109
+
110
+ def deliver!(mail)
111
+ #Mail::NotesMailer.deliveries << mail
112
+
113
+ destinations ||= mail.destinations if mail.respond_to?(:destinations) && mail.destinations
114
+ if destinations.blank?
115
+ raise ArgumentError.new('At least one recipient (To, Cc or Bcc) is required to send a message')
116
+ end
117
+
118
+ log_debug "--- log mail ---"
119
+ log_debug "destinations : "
120
+ log_debug destinations
121
+ log_debug "mail to : "
122
+ log_debug mail.to
123
+ log_debug "mail cc : "
124
+ log_debug mail.cc
125
+ log_debug "mail bcc : "
126
+ log_debug mail.bcc
127
+ log_debug "mail subject : "
128
+ log_debug mail.subject
129
+ log_debug "mail body : "
130
+ log_debug mail.body.to_s
131
+ log_debug "--- end ---"
132
+
133
+ new_mail = @notes_db.CreateDocument
134
+ new_mail.replaceItemValue("Form",'Memo')
135
+ new_mail.replaceItemValue("SendTo",mail.to)
136
+ new_mail.replaceItemValue("CopyTo",mail.cc)
137
+ new_mail.replaceItemValue("BlindCopyTo",mail.bcc)
138
+ new_mail.replaceItemValue("Subject",mail.subject)
139
+
140
+ #new_mail.replaceItemValue("Body", mail.body.to_s)
141
+ rti = new_mail.CreateRichTextItem("Body")
142
+ rti.AppendText( mail.body.to_s)
143
+ rti.AddNewLine()
144
+ rti.AppendText( "\nfrom #{mail.from.to_s}\n") if mail.from.to_s.size > 0
145
+ log_debug("\nfrom #{mail.from.to_s}\n") if mail.from.to_s.size > 0
146
+
147
+ mail.files_to_attach.each do |filename|
148
+ log_debug "attach: " + filename
149
+ # EMBED_ATTACHMENT (1454), EMBED_OBJECT (1453), EMBED_OBJECTLINK (1452)
150
+ rti.EmbedObject(1454,File.basename(filename),filename) # 1454 == EMBED_ATTACHMENT
151
+ end
152
+ new_mail.Send(0)
153
+
154
+ self
155
+ end
156
+
157
+ def NotesMailer.init_logger(debug)
158
+ FileUtils::mkdir_p("#{Dir.pwd}/log")
159
+ @@logger = Log4r::Logger.new("notes_mailer_logger")
160
+
161
+ if debug
162
+ puts "see logfile: #{Dir.pwd}/log/notes_mailer.log"
163
+ log_level = Log4r::DEBUG
164
+ else
165
+ log_level = Log4r::INFO
166
+ end
167
+
168
+ Log4r::FileOutputter.new('logfile',
169
+ :filename=>"#{Dir.pwd}/log/notes_mailer.log",
170
+ :trunc=>false,
171
+ :level=> log_level)
172
+
173
+ @@logger.add('logfile')
174
+
175
+ end
176
+ def log_info(*args, &block)
177
+ if @@logger
178
+ @@logger.info(*args, &block)
179
+ end
180
+ end
181
+ def log_debug(*args, &block)
182
+ if @@logger
183
+ p args
184
+ @@logger.debug(*args, &block)
185
+ end
186
+ end
187
+
188
+ end
189
+ end
@@ -0,0 +1,30 @@
1
+ require "rubygems"
2
+
3
+ spec = Gem::Specification.new do |s|
4
+ s.name = %q{notes_mailer}
5
+ s.version = "0.0.1"
6
+ s.authors = ["Elias Kugler"]
7
+ s.email = %q{groesser3@gmail.com}
8
+ s.files = Dir["lib/**/*"] + Dir["bin/**/*"] + Dir["test/**/*"]+ Dir["*.rb"] + ["MIT-LICENSE","notes_mailer.gemspec"]
9
+ s.platform = Gem::Platform::RUBY
10
+ s.has_rdoc = true
11
+ s.extra_rdoc_files = ["README.rdoc", "CHANGELOG.rdoc"]
12
+ s.require_paths = ["lib"]
13
+ s.summary = %q{Small gem that uses IBM Lotus Notes to deliver your e-mails.}
14
+ s.description = %q{NotesMailer allows you to send emails using your local IBM Lotus Notes installation. It is implemented by wrapping the Lotus Notes-win32ole-api as a custom delivery method for Mail. The usage is very similar to the SMTP delivery method in the popular Mail-gem.}
15
+ s.files.reject! { |fn| fn.include? "CVS" }
16
+ s.require_path = "lib"
17
+ #s.default_executable = %q{}
18
+ #s.executables = [""]
19
+ s.homepage = %q{http://rubyforge.org/projects/notesmailer/}
20
+ s.rubyforge_project = %q{notesmailer}
21
+ s.add_dependency("mail", ">= 2.2.1")
22
+ s.add_dependency("log4r", ">=1.0.5")
23
+
24
+ end
25
+
26
+
27
+ if $0 == __FILE__
28
+ Gem.manage_gems
29
+ Gem::Builder.new(spec).build
30
+ end
@@ -0,0 +1,112 @@
1
+ require 'log4r'
2
+ require 'fileutils'
3
+
4
+ # mock
5
+ class NotesValues
6
+ def initialize(arr=[])
7
+ @arr=arr
8
+ end
9
+ def Values
10
+ @arr
11
+ end
12
+ end
13
+
14
+ class NotesDocument
15
+ attr_accessor :uid, :deleted, :notes_values
16
+ def initialize
17
+ @deleted = false
18
+ @notes_values = {}
19
+ end
20
+ def UniversalID
21
+ return @uid
22
+ end
23
+ def GetFirstItem(key)
24
+ @notes_values[key]
25
+ end
26
+ def LastModified
27
+ '2009-12-02T16:01:21+00:00'
28
+ end
29
+ def IsDeleted
30
+ @deleted
31
+ end
32
+ def replaceItemValue(key, value)
33
+ @notes_values[key] = value
34
+ end
35
+ def Send(para)
36
+
37
+ end
38
+ def CreateRichTextItem(name)
39
+ CreateRichTextItem.new(name)
40
+ end
41
+ end
42
+
43
+ class CreateRichTextItem
44
+ def initialize(name)
45
+ end
46
+ def AppendText(text)
47
+ end
48
+ def AddNewLine()
49
+ end
50
+ def EmbedObject(type, name, filename)
51
+ end
52
+ end
53
+
54
+ class NotesView
55
+ def initialize
56
+ @cursor = -1
57
+ @elements = []
58
+ end
59
+
60
+ def GetLastDocument
61
+ if @elements.size == 0
62
+ return false
63
+ else
64
+ @cursor = @elements.size-1
65
+ return @elements[@cursor]
66
+ end
67
+ end
68
+ def GetPrevDocument(entry)
69
+ @cursor -= 1
70
+ if @cursor < 0
71
+ return false
72
+ else
73
+ return @elements[@cursor]
74
+ end
75
+ end
76
+ end
77
+
78
+ class NotesDB
79
+ def initialize(db)
80
+ end
81
+ def GetView(view)
82
+ NotesView.new
83
+ end
84
+ def isOpen
85
+ true
86
+ end
87
+ def CreateDocument
88
+ NotesDocument.new
89
+ end
90
+ end
91
+
92
+
93
+ class WIN32OLE # NotesSession
94
+ def initialize(app)
95
+ end
96
+ def Initialize(pwd)
97
+ end
98
+ def GetDatabase(server, db)
99
+ NotesDB.new(db)
100
+ end
101
+ def WIN32OLE.init_logger
102
+ FileUtils::mkdir_p("#{Dir.pwd}/log")
103
+ @@logger = Log4r::Logger.new("win32ole_logger")
104
+ Log4r::FileOutputter.new('win32ole_log',
105
+ :filename=>"#{Dir.pwd}/log/win32ole.log",
106
+ :trunc=>false,
107
+ :level=>Log4r::INFO)
108
+ @@logger.add('win32ole_log')
109
+ end
110
+ WIN32OLE.init_logger
111
+
112
+ end
@@ -0,0 +1,26 @@
1
+ $:.unshift '../lib'
2
+
3
+ require 'rubygems'
4
+ require 'notes_mailer'
5
+
6
+ Mail.defaults do
7
+ delivery_method Mail::NotesMailer, { :adress => "", # local database
8
+ :db => 'notes_db.nsf',
9
+ :user_name => 'myname',
10
+ :password => '',
11
+ #:mock_win32ole => true, # test without using Lotus Notes
12
+ #:logger => true,
13
+ #:debug => true
14
+ }
15
+
16
+ end
17
+
18
+ Mail.deliver do
19
+ to 'user@test.com'
20
+ from 'you@test.com'
21
+ subject 'test'
22
+ body 'hello'
23
+ add_file File.join(Dir.pwd, 'test_notes_mailer.rb')
24
+
25
+ end
26
+
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: notes_mailer
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Elias Kugler
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-11-08 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: mail
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 2
29
+ - 2
30
+ - 1
31
+ version: 2.2.1
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: log4r
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 1
43
+ - 0
44
+ - 5
45
+ version: 1.0.5
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ description: NotesMailer allows you to send emails using your local IBM Lotus Notes installation. It is implemented by wrapping the Lotus Notes-win32ole-api as a custom delivery method for Mail. The usage is very similar to the SMTP delivery method in the popular Mail-gem.
49
+ email: groesser3@gmail.com
50
+ executables: []
51
+
52
+ extensions: []
53
+
54
+ extra_rdoc_files:
55
+ - README.rdoc
56
+ - CHANGELOG.rdoc
57
+ files:
58
+ - lib/notes_mailer.rb
59
+ - test/mock/win32ole/win32ole.rb
60
+ - test/test_notes_mailer.rb
61
+ - MIT-LICENSE
62
+ - notes_mailer.gemspec
63
+ - README.rdoc
64
+ - CHANGELOG.rdoc
65
+ has_rdoc: true
66
+ homepage: http://rubyforge.org/projects/notesmailer/
67
+ licenses: []
68
+
69
+ post_install_message:
70
+ rdoc_options: []
71
+
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ segments:
79
+ - 0
80
+ version: "0"
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ requirements: []
89
+
90
+ rubyforge_project: notesmailer
91
+ rubygems_version: 1.3.6
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: Small gem that uses IBM Lotus Notes to deliver your e-mails.
95
+ test_files: []
96
+