Class: Malone
- Inherits:
-
Object
- Object
- Malone
- Defined in:
- lib/malone.rb,
lib/malone/test.rb
Defined Under Namespace
Classes: Configuration
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Class Method Summary collapse
- .connect(options = {}) ⇒ Object
- .current ⇒ Object
- .deliver(dict) ⇒ Object
- .deliveries ⇒ Object
- .reset_deliveries ⇒ Object
Instance Method Summary collapse
- #deliver(*args) {|mail| ... } ⇒ Object
- #envelope(dict) ⇒ Object
-
#initialize(config) ⇒ Malone
constructor
A new instance of Malone.
Constructor Details
#initialize(config) ⇒ Malone
Returns a new instance of Malone.
27 28 29 |
# File 'lib/malone.rb', line 27 def initialize(config) @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
7 8 9 |
# File 'lib/malone.rb', line 7 def config @config end |
Class Method Details
.connect(options = {}) ⇒ Object
9 10 11 12 13 |
# File 'lib/malone.rb', line 9 def self.connect( = {}) @config = Configuration.new() current end |
.current ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/malone.rb', line 15 def self.current unless defined?(@config) raise RuntimeError, "Missing configuration: Try doing `Malone.connect`." end return new(@config) end |
.deliver(dict) ⇒ Object
23 24 25 |
# File 'lib/malone.rb', line 23 def self.deliver(dict) current.deliver(dict) end |
.deliveries ⇒ Object
4 5 6 |
# File 'lib/malone/test.rb', line 4 def self.deliveries @deliveries ||= [] end |
.reset_deliveries ⇒ Object
8 9 10 |
# File 'lib/malone/test.rb', line 8 def self.reset_deliveries @deliveries = nil end |
Instance Method Details
#deliver(*args) {|mail| ... } ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/malone.rb', line 31 def deliver(dict) mail = envelope(dict) yield mail if block_given? smtp = Net::SMTP.new(config.host, config.port) if config.force_tls smtp.enable_starttls elsif config.tls smtp.enable_starttls_auto end begin smtp.start(config.domain, config.user, config.password, config.auth) smtp.(mail.to_s, mail.from.first, *mail.recipients) ensure smtp.finish if smtp.started? end end |
#envelope(dict) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/malone.rb', line 51 def envelope(dict) envelope = Kuvert.new envelope.from = dict[:from] envelope.to = dict[:to] envelope.replyto = dict[:replyto] envelope.cc = dict[:cc] if dict[:cc] envelope.bcc = dict[:bcc] if dict[:bcc] envelope.text = dict[:text] envelope.rawhtml = dict[:html] if dict[:html] envelope.subject = dict[:subject] envelope.attach(dict[:attach]) if dict[:attach] envelope.(*dict[:attach_as]) if dict[:attach_as] return envelope end |