Class: Resend::Mailer

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Mailer

Returns a new instance of Mailer.



8
9
10
11
12
13
# File 'lib/resend/mailer.rb', line 8

def initialize(config)
  @config = config
  raise Resend::ResendError.new("Config requires api_key", @config) unless @config.has_key?(:api_key)
  @settings = { return_response: true } # avoids NilError exception
  @resend_client = Resend::Client.new config[:api_key]
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



6
7
8
# File 'lib/resend/mailer.rb', line 6

def config
  @config
end

#settingsObject

Returns the value of attribute settings.



6
7
8
# File 'lib/resend/mailer.rb', line 6

def settings
  @settings
end

Instance Method Details

#deliver!(mail) ⇒ Object



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

def deliver!(mail)
  params = {
    from: mail[:from].to_s,
    to: mail.to,
    subject: mail.subject,
  }
  params[:cc] = mail[:cc] if mail[:cc].present?
  params[:bcc] = mail[:bcc] if mail[:bcc].present?
  params[:reply_to] = mail[:reply_to] if mail[:reply_to].present?
  params[:html] = mail.body.decoded

  resp = @resend_client.send_email(params)

  if resp[:error].nil? then
    mail.message_id = resp[:id]
  end

  resp
end

#resend_clientObject



35
36
37
# File 'lib/resend/mailer.rb', line 35

def resend_client
  @resend_client
end