Hi guys, nice being a part of this community, sorry for my english if some sentences doesnt make much sense. Well, my question is i have a file, i liked to make a script that for example, in 1 or 2 hours would get the txt file where its located in the same folder of the script and send it to my email.
Could you guys give me some pointers?
Be well

I know this is a C++ forum, but why don't you just do this in Ruby?

Otherwise, make a thread that sleeps for 60 seconds and increments a counter by 1, when the counter is 120 (2 hours), reset it to 0 and execute the file read.

Save the file to a variable and then send an email with winsock. There are myriad socket libraries with tons of functionality, such as the boost socket library.

If you do this in the Ruby language, the program will be under 10 lines of code.

Good luck!

Edited 6 Years Ago by Unimportant: n/a

In ruby? i never programed it in ruby, how would i do it?

require 'net/smtp'
$message = ''
file = File.new("file_path_name_etc.txt", "r")
  while (line = file.gets)
    message << "#{line}"
  end
file.close
Net::SMTP.start('smtp.domain.com', 25) do |smtp|
  smtp.open_message_stream('from_addr', [to_addr]) do |f|
    f.puts 'From: youremail@address.com'
    f.puts 'To: recipient@domain.com'
    f.puts 'Subject: your subject'
    f.puts message
  end
end

## Pretty much sums it up, minus the calls to sleep, but ruby scripts can be run as
## services/daemons, you could also call it as a cron, or have it check the time
## while running.

### AUTHENTICATION ### REPLACE THE LINE ABOVE THAT HAS SMTP.start
# PLAIN
  Net::SMTP.start('your.smtp.server', 25, 'mail.from.domain','ACCOUNT', 'PASS', :plain)
  # LOGIN
  Net::SMTP.start('your.smtp.server', 25, 'mail.from.domain','ACCOUNT', 'PASS', :login)
  # CRAM MD5
  Net::SMTP.start('your.smtp.server', 25, 'mail.from.domain','ACCOUNT', 'PASS', :cram_md5)

Good luck!

Edited 6 Years Ago by Unimportant: n/a

wooooo, really nice, and symple, goota learn more about the language, any websites whit good info that you could advice me Unimportant
:)

I'd recommend you start by reading "Why's Poignant Guide to Ruby", it was my first introduction to the language as well. I found to be exceptional.

After that, "Rails Recipes" and "Advanced Rails Recipes" are great books.

Why's guide is free to download, the other two you have to buy. If you want some website references www.ruby-lang.org has many recommendations.

Best of luck!

This article has been dead for over six months. Start a new discussion instead.