Class: DistributionWrappers::Sendgrid

Inherits:
Email
  • Object
show all
Includes:
SendGrid
Defined in:
lib/distribution_wrappers/sendgrid/sendgrid.rb

Instance Attribute Summary

Attributes inherited from Base

#params

Instance Method Summary collapse

Methods inherited from Email

#prepare

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from DistributionWrappers::Base

Instance Method Details

#send_message(recipient) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/distribution_wrappers/sendgrid/sendgrid.rb', line 5

def send_message(recipient)
  super
  email = recipient['identifier']
   = {}
  ["user_id"] = @params[:user].id if @params[:user]
  
  ### Send Sendgrid Email ###
  
  # Build request
  data = {"metadata" => }
          
  # Post to SendGrid
  api_key = Keys.sendgrid.studio.api_key
  client = SendGrid::API.new(:api_key => api_key)
  
  send_from = {
      :email => "#{@params[:custom_opts]['send_from']}@#{Keys.sendgrid.studio.send_from_domain}",
      :name => @params[:user].display_name
    }
    
  from = SendGrid::Email.new(send_from)
  subject = @params[:subject]
  to = SendGrid::Email.new(email: email)
  content = SendGrid::Content.new(type: 'text/html', value: @message)
  mail = Mail.new(from, subject, to, content)
  
  
  response = client.client.mail._('send').post(request_body: mail.to_json)
end