Class: Jenode::Email

Inherits:
Object
  • Object
show all
Defined in:
lib/jenode/email.rb

Constant Summary collapse

DEFAULT_SELECTOR =
'default'
CLICK_SUBDOMAIN =
'click'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Email

Returns a new instance of Email.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/jenode/email.rb', line 24

def initialize(options = {})
  @source_ip = options[:source_ip]
  @recipient = options[:recipient]
  @sender    = options[:sender]
  @template  = options[:template]
  @dkim_key  = options[:dkim_key]
  @template_vars = {
    'sender'         => sender,
    'recipient'      => recipient,
    'source_ip'      => source_ip,
    'sender_host'    => sender_host,
    'recipient_host' => recipient_host
  }
  @template_vars.merge!(options[:template_vars] || {})
  @template_binding = OpenStruct.new(@template_vars).instance_eval { binding }
  @dont_touch_template = options[:dont_touch_template]
  @utm_attributes = options[:utm_attributes]
end

Instance Attribute Details

#dkim_keyObject (readonly)

Returns the value of attribute dkim_key.



19
20
21
# File 'lib/jenode/email.rb', line 19

def dkim_key
  @dkim_key
end

#dont_touch_templateObject (readonly)

Returns the value of attribute dont_touch_template.



19
20
21
# File 'lib/jenode/email.rb', line 19

def dont_touch_template
  @dont_touch_template
end

#recipientObject (readonly)

Returns the value of attribute recipient.



19
20
21
# File 'lib/jenode/email.rb', line 19

def recipient
  @recipient
end

#senderObject (readonly)

Returns the value of attribute sender.



19
20
21
# File 'lib/jenode/email.rb', line 19

def sender
  @sender
end

#source_ipObject (readonly)

Returns the value of attribute source_ip.



19
20
21
# File 'lib/jenode/email.rb', line 19

def source_ip
  @source_ip
end

#templateObject (readonly)

Returns the value of attribute template.



19
20
21
# File 'lib/jenode/email.rb', line 19

def template
  @template
end

#template_bindingObject (readonly)

Returns the value of attribute template_binding.



19
20
21
# File 'lib/jenode/email.rb', line 19

def template_binding
  @template_binding
end

#template_varsObject (readonly)

Returns the value of attribute template_vars.



19
20
21
# File 'lib/jenode/email.rb', line 19

def template_vars
  @template_vars
end

#utm_attributesObject (readonly)

Returns the value of attribute utm_attributes.



19
20
21
# File 'lib/jenode/email.rb', line 19

def utm_attributes
  @utm_attributes
end

Class Method Details

.mail_exchangers(mail_host) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/jenode/email.rb', line 7

def mail_exchangers(mail_host)
  @cache_mail_exchangers ||= {}
  mail_exchangers = @cache_mail_exchangers[mail_host]
  return mail_exchangers if mail_exchangers

  @cache_mail_exchangers[mail_host] = begin
    Resolv::DNS.open(nameserver: '8.8.8.8').getresources(mail_host, Resolv::DNS::Resource::IN::MX).
      sort_by(&:preference).map(&:exchange).map(&:to_s)
  end
end

Instance Method Details

#sendObject



43
44
45
46
47
48
49
50
# File 'lib/jenode/email.rb', line 43

def send
  data = cook_email
  mail_exchanger = mail_exchangers.sample
  smtp = Net::SMTPWithSourceIp.new(mail_exchanger, 25, source_ip)
  smtp.start(sender_host)
  smtp.send_message(data, sender, recipient)
  smtp.finish
end