Skip to content

Instantly share code, notes, and snippets.

@joelibaceta
Created January 25, 2019 15:07
Show Gist options
  • Save joelibaceta/7235a3ae2bedac55d3c9f86afde4aff3 to your computer and use it in GitHub Desktop.
Save joelibaceta/7235a3ae2bedac55d3c9f86afde4aff3 to your computer and use it in GitHub Desktop.
Mail Sender
source 'https://rubygems.org'
gem 'ruby-progressbar'
require 'net/http'
require 'uri'
require 'json'
require 'ruby-progressbar'
@@uri = URI.parse("http://api.internal.ml.com/internal/email/")
n_lines_on_file = `wc -l < user_ids_test`.to_i
puts "Lineas number: #{n_lines_on_file}"
@@progressbar = ProgressBar.create(
total: n_lines_on_file,
title: "Sending Mails",
format: "%a %b\u{15E7}%i %p%% %t",
progress_mark: ' ',
remainder_mark: "\u{FF65}"
)
def send_mail_to(id)
request = Net::HTTP::Post.new(@@uri)
request.body = JSON.dump({
"user_id" => id.to_i,
"template" => "V0V1_LG_COM_TPL",
"context" => {}
})
response = Net::HTTP.start(@@uri.hostname, @@uri.port, nil) do |http|
http.request(request)
end
string_response = JSON.parse(response.body)
@@progressbar.log("UserID: #{id.to_i} EmailID: #{string_response["email_id"]}")
end
File.open("user_ids.csv", "r") do |f|
f.each_line do |line|
send_mail_to(line)
@@progressbar.increment
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment