class DistributionWrappers::Sendgrid
Public Instance Methods
send_message(recipient)
click to toggle source
Calls superclass method
DistributionWrappers::Base#send_message
# File lib/distribution_wrappers/sendgrid/sendgrid.rb, line 5 def send_message(recipient) super email = recipient['identifier'] metadata = {} metadata["user_id"] = @params[:user].id if @params[:user] ### Send Sendgrid Email ### # Build request data = {"metadata" => 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