136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
# File 'lib/logstash/outputs/email.rb', line 136
def receive(event)
@logger.debug? and @logger.debug("Creating mail with these settings : ", :via => @via, :options => @options, :from => @from, :to => @to, :cc => @cc, :bcc => @bcc, :subject => @subject, :body => @body, :content_type => @contenttype, :htmlbody => @htmlbody, :attachments => @attachments, :custom_headers => @custom_headers)
formatedSubject = event.sprintf(@subject)
formattedBody = event.sprintf(@body)
formattedHtmlBody = event.sprintf(@htmlbody)
mail = Mail.new
mail.from = event.sprintf(@from)
mail.to = event.sprintf(@to)
if @replyto
mail.reply_to = event.sprintf(@replyto)
end
mail.cc = event.sprintf(@cc)
mail.bcc = event.sprintf(@bcc)
mail.subject = formatedSubject
@custom_headers.each do |key, value|
mail.[event.sprintf(key)] = event.sprintf(value)
end
if @htmlbody.empty? and @template_file.nil?
formattedBody.gsub!(/\\n/, "\n") mail.body = formattedBody
else
mail.text_part = Mail::Part.new do
content_type "text/plain; charset=UTF-8"
formattedBody.gsub!(/\\n/, "\n") body formattedBody
end
if @template_file.nil?
mail.html_part = Mail::Part.new do
content_type "text/html; charset=UTF-8"
body formattedHtmlBody
end
else
templatedHtmlBody = Mustache.render(@htmlTemplate, event.to_hash)
mail.html_part = Mail::Part.new do
content_type "text/html; charset=UTF-8"
body templatedHtmlBody
end
end
end
@attachments.each do |fileLocation|
mail.add_file(fileLocation)
end @logger.debug? and @logger.debug("Sending mail with these values : ", :from => mail.from, :to => mail.to, :cc => mail.cc, :bcc => mail.bcc, :subject => mail.subject)
begin
mail.deliver!
rescue StandardError => e
@logger.error("Something happen while delivering an email", :exception => e)
@logger.debug? && @logger.debug("Processed event: ", :event => event)
end
end
|