Class: JavaMail::Config

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

Instance Method Summary collapse

Constructor Details

#initialize(settings = {}) ⇒ Config

Returns a new instance of Config.



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

def initialize(settings = {})
  @settings = settings
  @settings[:protocol] ||= :none
  
  unless [:smtp, :smtps, :none].include?(@settings[:protocol])
    raise JavaMailError.new("Invalid protocol #{@settings[:protocol].to_s}")
  end
end

Instance Method Details

#auth?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/java_mail/config.rb', line 43

def auth?
  @settings[:user_name] && @settings[:password]
end

#debug?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/java_mail/config.rb', line 35

def debug?
  @settings[:debug] ? true : false
end

#dkim?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/java_mail/config.rb', line 39

def dkim?
  @settings[:dkim] && @settings[:dkim][:domain] && @settings[:dkim][:selector] && @settings[:dkim][:key_file]
end

#session_propertiesObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/java_mail/config.rb', line 12

def session_properties
  props = java.util.Properties.new()
  return props if @mode == :none
  
  # We only support SMTP (plan and SSL) for now
  props.put('mail.transport.protocol', @settings[:protocol].to_s);
  
  # Let's do the basic mapping for SMTP settings
  session_property_key_map.each_pair do |key, property|
    props.put(property, @settings[key].to_s) if @settings[key]
  end
  
  # Enable authentication and encryption
  props.put('mail.smtp.auth', 'true') if self.auth?
  props.put('mail.smtp.ssl.protocols', 'SSLv3 TLSv1') if @settings[:protocol] == :smtps;
  
  # Debugging
  props.put('mail.debug', 'true') if self.debug?
  
  # Return
  props
end