Class: JavaMail::Mailer

Inherits:
Object
  • Object
show all
Defined in:
lib/java_mail/mailer.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings = {}) ⇒ Mailer

Returns a new instance of Mailer.



3
4
5
6
7
8
# File 'lib/java_mail/mailer.rb', line 3

def initialize(settings = {})
  @config = JavaMail::Config.new(settings)
  @session = JavaMail::Java::Session.getInstance(@config.session_properties)
  @session.setDebug(@config.debug?)      
  @transport = @session.getTransport
end

Class Method Details

.open(settings, &block) ⇒ Object



10
11
12
# File 'lib/java_mail/mailer.rb', line 10

def self.open(settings, &block)
  self.new(settings).open(&block)
end

Instance Method Details

#open(&block) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/java_mail/mailer.rb', line 14

def open(&block)
  begin
    open_transport unless transport_ready?
    block.call(self)
  rescue Exception => e
    raise JavaMail::JavaMailError.new(e)
  ensure
    close_transport if transport_ready?
  end 
end

#send_message(tmail) ⇒ Object



25
26
27
28
# File 'lib/java_mail/mailer.rb', line 25

def send_message(tmail)
  raise JavaMail::JavaMailError.new("JavaMail Transport is not connected") unless transport_ready?
  send_message_to_transport(tmail, @transport)
end