Class: Incoming::Strategies::Sendgrid

Inherits:
Object
  • Object
show all
Includes:
Incoming::Strategy
Defined in:
lib/incoming/strategies/sendgrid.rb

Instance Attribute Summary

Attributes included from Incoming::Strategy

#message

Instance Method Summary collapse

Methods included from Incoming::Strategy

included

Constructor Details

#initialize(request) ⇒ Sendgrid

Returns a new instance of Sendgrid.



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
# File 'lib/incoming/strategies/sendgrid.rb', line 6

def initialize(request)
  params = request.params.dup
  envelope = JSON.parse(params['envelope'])

  # TODO: Properly handle encodings
  # encodings = JSON.parse(params['charsets'])

  @message = Mail.new do
    header params['headers']
    from params['from']
    to envelope['to'].first
    subject params['subject']

    body params['text']

    html_part do
      content_type 'text/html; charset=UTF-8'
      body params['html']
    end if params['html']

    1.upto(params['attachments'].to_i).each do |num|
      attachment = params["attachment#{num}"]
      add_file(:filename => attachment.original_filename, :content => attachment.read)
    end
  end
end