yakischloba-em-mailer 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +47 -0
- data/em-mailer.gemspec +16 -0
- data/lib/em-mailer.rb +55 -0
- metadata +65 -0
data/README.rdoc
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
== em-mailer
|
2
|
+
|
3
|
+
Simple wrapper for EventMachine SMTP client, makes sending mail with EM easy!
|
4
|
+
It uses tmail or tmail-pure for creating the mail messages. tmail-pure has no C
|
5
|
+
and works on JRuby. Grab it here http://github.com/yakischloba/tmail-pure/tree/master
|
6
|
+
|
7
|
+
If you want, you can just pass your own TMail::Mail object to Mailer#send instead
|
8
|
+
of using the Mailer#mail helper. This would be useful for fancy things like attachments.
|
9
|
+
|
10
|
+
== Synopsis
|
11
|
+
|
12
|
+
require 'rubygems'
|
13
|
+
require 'eventmachine'
|
14
|
+
require 'em-mailer'
|
15
|
+
|
16
|
+
mailer = EventMachine::Mailer.new(
|
17
|
+
:domain => 'somedomain.com',
|
18
|
+
:host => 'smtp.somemailserver.com',
|
19
|
+
:username => 'spaceman',
|
20
|
+
:password => 'afraidofasteroids',
|
21
|
+
)
|
22
|
+
|
23
|
+
# These callbacks will be executed for all mails sent with the mailer
|
24
|
+
mailer.callback { $stdout.puts "Sent successfully!"}
|
25
|
+
mailer.errback {|e| $stdout.puts "you blew it: #{e}"}
|
26
|
+
|
27
|
+
EM.run {
|
28
|
+
mailer.mail(
|
29
|
+
:to => "asteroid@largegalaxy.com",
|
30
|
+
:from => "spaceman@spacestation.com",
|
31
|
+
:subject => "zomg",
|
32
|
+
:body => "<html><body><h1>HEY</h1><p>Please don't hit me!</p></body></html>",
|
33
|
+
:html => true
|
34
|
+
)
|
35
|
+
}
|
36
|
+
|
37
|
+
== Other options
|
38
|
+
|
39
|
+
# Set the port, defaults to 25.
|
40
|
+
:port => Integer
|
41
|
+
# Enable SSL on the connection. Note that this is just normal SSL,
|
42
|
+
# and not the STARTTLS command in the SMTP protocol.
|
43
|
+
:starttls => true/false
|
44
|
+
|
45
|
+
== Issues
|
46
|
+
|
47
|
+
The EM client only supports 'plain' auth for now.
|
data/em-mailer.gemspec
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "em-mailer"
|
3
|
+
s.version = "0.0.2"
|
4
|
+
s.date = "2009-08-05"
|
5
|
+
s.authors = ["Jake Douglas"]
|
6
|
+
s.email = "jakecdouglas@gmail.com"
|
7
|
+
s.has_rdoc = false
|
8
|
+
s.add_dependency('eventmachine')
|
9
|
+
s.summary = "Simple wrapper for Eventmachine SMTP client"
|
10
|
+
s.homepage = "http://www.github.com/yakischloba/em-mailer"
|
11
|
+
s.description = "Simple wrapper for Eventmachine SMTP client"
|
12
|
+
s.files =
|
13
|
+
["em-mailer.gemspec",
|
14
|
+
"README.rdoc",
|
15
|
+
"lib/em-mailer.rb"]
|
16
|
+
end
|
data/lib/em-mailer.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'em/protocols/smtpclient'
|
2
|
+
begin
|
3
|
+
require 'tmail'
|
4
|
+
rescue LoadError
|
5
|
+
require 'tmail-pure'
|
6
|
+
end
|
7
|
+
|
8
|
+
module EventMachine
|
9
|
+
class Mailer
|
10
|
+
def initialize(options)
|
11
|
+
@options = options
|
12
|
+
if @options[:username] and @options[:password]
|
13
|
+
@options[:auth] = {}
|
14
|
+
@options[:auth][:username] = @options.delete(:username)
|
15
|
+
@options[:auth][:password] = @options.delete(:password)
|
16
|
+
@options[:auth][:type] = :plain
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def callback(proc=nil, &blk)
|
21
|
+
@callback = proc || blk
|
22
|
+
end
|
23
|
+
|
24
|
+
def errback(proc=nil, &blk)
|
25
|
+
@errback = proc || blk
|
26
|
+
end
|
27
|
+
|
28
|
+
def send(msg)
|
29
|
+
opts = {
|
30
|
+
# Can email have multiple 'from's? I duno, but this client doesn't like it.
|
31
|
+
:from => msg.from.is_a?(Array) ? msg.from.first : msg.from,
|
32
|
+
:to => msg.respond_to?(:destinations) ? msg.destinations : msg.to,
|
33
|
+
:content => "#{msg.to_s}\r\n.\r\n",
|
34
|
+
:verbose => false,
|
35
|
+
:port => 25,
|
36
|
+
:starttls => false
|
37
|
+
}.merge(@options)
|
38
|
+
|
39
|
+
email = EM::Protocols::SmtpClient.send(opts)
|
40
|
+
email.callback &@callback if @callback
|
41
|
+
email.errback &@errback if @errback
|
42
|
+
end
|
43
|
+
|
44
|
+
def mail(opts)
|
45
|
+
msg = TMail::Mail.new
|
46
|
+
msg.to = opts[:to]
|
47
|
+
msg.from = opts[:from]
|
48
|
+
msg.subject = opts[:subject]
|
49
|
+
msg.body = opts[:body]
|
50
|
+
msg.set_content_type("text", "html") if opts[:html]
|
51
|
+
self.send(msg)
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yakischloba-em-mailer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jake Douglas
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-08-05 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: eventmachine
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description: Simple wrapper for Eventmachine SMTP client
|
26
|
+
email: jakecdouglas@gmail.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files: []
|
32
|
+
|
33
|
+
files:
|
34
|
+
- em-mailer.gemspec
|
35
|
+
- README.rdoc
|
36
|
+
- lib/em-mailer.rb
|
37
|
+
has_rdoc: false
|
38
|
+
homepage: http://www.github.com/yakischloba/em-mailer
|
39
|
+
licenses:
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: "0"
|
50
|
+
version:
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "0"
|
56
|
+
version:
|
57
|
+
requirements: []
|
58
|
+
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 1.3.5
|
61
|
+
signing_key:
|
62
|
+
specification_version: 2
|
63
|
+
summary: Simple wrapper for Eventmachine SMTP client
|
64
|
+
test_files: []
|
65
|
+
|