Class: JavaMail::Config

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

Constant Summary collapse

PROTOCOLS =
[:smtp, :smtps, :gm]

Instance Method Summary collapse

Constructor Details

#initialize(settings = {}) ⇒ Config

Returns a new instance of Config.



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

def initialize(settings = {})
  @settings = settings
  
  unless PROTOCOLS.include?(@settings[:protocol])
    raise JavaMailError.new("Protocol #{@settings[:protocol].inspect} is not one of the supported protocols: #{PROTOCOLS.inspect}")
  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



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 13

def session_properties
  props = java.util.Properties.new()
  
  # 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