Created
June 3, 2014 20:31
-
-
Save Porta/1635ee652955dcf86132 to your computer and use it in GitHub Desktop.
Pura alegría.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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