The best way to send generated numbers to an email address

Hi,
I’m writing an application that generate some sort of prepaid cards,
each
card with a PIN and a serial number. All serials and PINs are being
hashed
when saved to the database. For more security, I need the generated
numbers
to be sent via email to the Admin when they generated, there is no way
for
the admin to view the numbers from inside the application.
The process is as the following: Admin chooses to generate 1000 new
cards
(for example) --> Numbers are sent to the Admin by email before they get
hashed --> numbers are hashed and saved to the database.

The above scenario works for me without problems, right now the
generated
numbers are being sent as plain text in the body of the email message,
my
question is that good for large amount of numbers (thousands of cards)?
Or
should I export them as a CSV file and send it as attachment? I checked
FasterCSV and the standard Ruby CSV library but as I understand they
wouldn’t work for huge amount of data. Should I consider exporting to
Excel
file? Or do you think that it’s just fine to send them in the body of
the
email message? Or do you suggest some alternative way that I didn’t
think
about?

For reference: this is the generate method in the controller:

def generate
@cards = {}
params[:card][:number_of_cards].to_i.times do
pin = rand(999999999999).to_s.center(12, rand(9).to_s)
serial = rand(999999999999).to_s.center(12, rand(9).to_s)
@cards[serial] = pin
Card.create({:pin => pin, :serial => serial})
end
PostOffice.deliver_send_cards(@cards)
redirect_to(cards_path)
end

In the model:

def before_save
self.pin = Card.encrypt(pin)
self.serial = Card.encrypt(serial)
end

In the Action Mailder:

def send_cards(cards)

@recipients = "[email protected]"
@from = "someaddress"
headers  "Reply-to" => "[email protected]"
@subject = "New generated cards"
@sent_on = Time.now

body[:cards] = cards

end

send_cards.html.erb:

<[email protected] do |a,b| %>
<%= a +","+ b %>
<%end%>

Thanks in advance

I don’t see any problem with sending an email that’s multiple
thousands of lines long.

One thing you might consider, though: format the email so that it
sends in a “textualized table”… i.e. instead of one number per line,
have 4 or 5 with tab stops or even spacings, so it lays out like a
table. Look at the Array function “in_groups_of” for grouping the
cards array in chunks.

Also, shouldn’t you slap some public/private key encryption on that?
Sending card numbers in the clear via email is probably not a wise
idea. You could encrypt the body of the email with your public key,
then decrypt it on the admin’s email app with the admin’s private key.

-Danimal

Sure!

http://www.ahgsoftware.com/articles/2007/03/18/how-to-encrypt-ruby-on-rails-mail-with-gnupg
http://agilewebdevelopment.com/plugins/gnupg

-Danimal

Hi Danimal,
Thank you for your useful comments.
About encryption with with my public key, can rails do this when sending
the
email?

Regards

On 13/04/2008, Danimal [email protected] wrote:

I’m writing an application that generate some sort of prepaid cards,
(for example) → Numbers are sent to the Admin by email before they get
wouldn’t work for huge amount of data. Should I consider exporting to
@cards = {}
In the model:

send_cards.html.erb:

<[email protected] do |a,b| %>
<%= a +“,”+ b %>
<%end%>

Thanks in advance


Anas Marrawi
Visit me at: www.anasonline.net