Skip to content

Instantly share code, notes, and snippets.

@Porta
Created June 3, 2014 20:31
Show Gist options
  • Select an option

  • Save Porta/1635ee652955dcf86132 to your computer and use it in GitHub Desktop.

Select an option

Save Porta/1635ee652955dcf86132 to your computer and use it in GitHub Desktop.
Pura alegría.
require "malone"
require "mote"
load('importer.rb')
mailer = Malone.connect(url: "smtp://foo%40localhost:pistola@localhost:1025",domain: "localhost")
data = File.read('mails.csv').encode("UTF-8", invalid: :replace, undef: :replace, replace: "?")
imported_data = Importer.import(data)
template = File.read('templates/mail.mote')
mote = Mote.parse(template, self, imported_data[0].keys)
imported_data.each do |obj|
Malone.deliver(
from: "test@localhost",
to: obj["email"],
subject: "Sorpresa!",
text: mote.call(obj)
)
end
# encoding: utf-8
module Importer
class << self
def import(stream)
require 'csv'
csv = CSV.parse(stream, :col_sep => ',', :quote_char => '"')
fields = csv.shift
csv.collect { |record| Hash[*fields.zip(record).flatten ] }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment