Class: Jenode::Email
- Inherits:
-
Object
- Object
- Jenode::Email
- Defined in:
- lib/jenode/email.rb
Constant Summary collapse
- DEFAULT_SELECTOR =
'default'- CLICK_SUBDOMAIN =
'click'
Instance Attribute Summary collapse
-
#dkim_key ⇒ Object
readonly
Returns the value of attribute dkim_key.
-
#dont_touch_template ⇒ Object
readonly
Returns the value of attribute dont_touch_template.
-
#recipient ⇒ Object
readonly
Returns the value of attribute recipient.
-
#sender ⇒ Object
readonly
Returns the value of attribute sender.
-
#source_ip ⇒ Object
readonly
Returns the value of attribute source_ip.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
-
#template_binding ⇒ Object
readonly
Returns the value of attribute template_binding.
-
#template_vars ⇒ Object
readonly
Returns the value of attribute template_vars.
-
#utm_attributes ⇒ Object
readonly
Returns the value of attribute utm_attributes.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Email
constructor
A new instance of Email.
- #send ⇒ Object
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( = {}) @source_ip = [:source_ip] @recipient = [:recipient] @sender = [:sender] @template = [:template] @dkim_key = [:dkim_key] @template_vars = { 'sender' => sender, 'recipient' => recipient, 'source_ip' => source_ip, 'sender_host' => sender_host, 'recipient_host' => recipient_host } @template_vars.merge!([:template_vars] || {}) @template_binding = OpenStruct.new(@template_vars).instance_eval { binding } @dont_touch_template = [:dont_touch_template] @utm_attributes = [:utm_attributes] end |
Instance Attribute Details
#dkim_key ⇒ Object (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_template ⇒ Object (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 |
#recipient ⇒ Object (readonly)
Returns the value of attribute recipient.
19 20 21 |
# File 'lib/jenode/email.rb', line 19 def recipient @recipient end |
#sender ⇒ Object (readonly)
Returns the value of attribute sender.
19 20 21 |
# File 'lib/jenode/email.rb', line 19 def sender @sender end |
#source_ip ⇒ Object (readonly)
Returns the value of attribute source_ip.
19 20 21 |
# File 'lib/jenode/email.rb', line 19 def source_ip @source_ip end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
19 20 21 |
# File 'lib/jenode/email.rb', line 19 def template @template end |
#template_binding ⇒ Object (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_vars ⇒ Object (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_attributes ⇒ Object (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
#send ⇒ Object
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.(data, sender, recipient) smtp.finish end |