Class: Fluent::SESOutput

Inherits:
BufferedOutput
  • Object
show all
Includes:
Mixin::PlainTextFormatter, SetTagKeyMixin, SetTimeKeyMixin
Defined in:
lib/fluent/plugin/out_ses.rb

Instance Method Summary collapse

Constructor Details

#initializeSESOutput

Returns a new instance of SESOutput.



9
10
11
12
# File 'lib/fluent/plugin/out_ses.rb', line 9

def initialize
  super
  require 'aws-sdk'
end

Instance Method Details

#startObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/fluent/plugin/out_ses.rb', line 29

def start
  super
  options = {}
  if @aws_key_id && @aws_sec_key
    options[:access_key_id]     = @aws_key_id
    options[:secret_access_key] = @aws_sec_key
  end
  @ses = AWS::SimpleEmailService.new options

  to_addresses  = @to.split ","
  if to_addresses.empty?
    raise Fluent::ConfigError, "To is not nil."
  end

  cc_addresses  = @cc.split ","
  bcc_addresses = @bcc.split ","

  @destination = {:to_addresses => to_addresses}
  unless cc_addresses.empty?
    @destination[:cc_addresses] = cc_addresses
  end
  unless bcc_addresses.empty?
    @destination[:bcc_addresses] = bcc_addresses
  end
  valid!
end

#write(chunk) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/fluent/plugin/out_ses.rb', line 56

def write(chunk)
  body_text = chunk.read.force_encoding "utf-8"

  options = {
    :source      => @from,
    :destination => @destination,
    :message => {
      :subject => {          :data => @subject},
      :body    => {:text => {:data => body_text}},
    },
  }
  reply_to_addresses = @reply_to_addresses.split ","
  unless reply_to_addresses.empty?
    options[:reply_to_addresses] = reply_to_addresses
  end

  begin
    res = @ses.client.send_email options
  rescue => e
    $log.error e.message
  end
end