lib/mutx/background_jobs/workers/email_sender.rb in mutx-0.1.17 vs lib/mutx/background_jobs/workers/email_sender.rb in mutx-0.1.18

- old
+ new

@@ -1,57 +1,71 @@ # encoding: utf-8 require 'mutx' require 'mail' require 'erb' require 'ostruct' +require 'byebug' #require 'sidekiq/testing/inline' module Mutx module Workers class EmailSender include Sidekiq::Worker - def perform(result_id, subject, email, name, id) + def perform(result_id, subject, email, name, id, type) Mail.defaults do delivery_method :smtp, { - address: 'smtp.gmail.com', - port: 587, - domain: 'gmail.com', - user_name: 'mutx.notifications@gmail.com', - password: "garbaqa2016", - authentication: 'plain', - enable_starttls_auto: true + address: Mutx::Support::Configuration.smtp_address, + port: Mutx::Support::Configuration.smtp_port, + domain: Mutx::Support::Configuration.smtp_domain, + user_name: Mutx::Support::Configuration.smtp_user, + password: Mutx::Support::Configuration.smtp_password, + authentication: Mutx::Support::Configuration.smtp_autentication, + enable_starttls_auto: Mutx::Support::Configuration.smtp_enable_start_tls_auto } end result = Mutx::Results::Result.get(result_id) template_path = (`pwd`+"/mutx/templates/mutx_template.html.erb").delete"\n" + template_body_path = (`pwd`+"/mutx/templates/mutx_body_template.html.erb").delete"\n" output = result.console_output status = result.status + info = "Only for TEST executions" + (info = output.match(/\d+\sscenarios\s+([^\/]+)/) + info_1 = info.to_s.delete"=========================" + info = info_1 + ) if type.to_s.downcase.eql? "test" + #seteo el template mail = Mail.new mail.content_type "multipart/mixed;" - data = OpenStruct.new(output: output, task_name: name, id: id, time: result.elapsed_time, status: status) + data = OpenStruct.new(output: output, task_name: name, id: id, time: result.elapsed_time, status: status, info: info) html_part = Mail::Part.new html_part.content_type = "text/html; charset=UTF-8" template = File.read(template_path) html_part.body = ERB.new(template).result(data.instance_eval { binding }) - mail.html_part = html_part + #mail.html_part = html_part #Adjunta al mail + #fin seteo template - mail.from 'Mutx <mutx@garbarino.com>' - mail.to "#{email}" + mail.from 'Mutx <your@email.sender.org>' + + mail.to "#{email}" mail.subject = "[MuTX] ==> #{subject}" File.open("result.html", "w") { |file| file.write("#{html_part.body}") } mail.add_file "result.html" - html_part.body "\nA continuacion se adjunta el resutado de la ejecucion solicitada. -.Equipo [MuTX].-" + html_part = Mail::Part.new + html_part.content_type = "text/html; charset=UTF-8" + template1 = File.read(template_body_path) + html_part.body = ERB.new(template1).result(data.instance_eval { binding }) + mail.html_part = html_part puts "ENVIANDO RESULTADO VIA MAIL" tries = 3 begin \ No newline at end of file