Skip to content

Instantly share code, notes, and snippets.

@alcabanillas-engh
Created November 25, 2008 05:21
Show Gist options
  • Save alcabanillas-engh/28797 to your computer and use it in GitHub Desktop.
Save alcabanillas-engh/28797 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'configatron'
require 'net/pop'
require 'net/smtp'
require 'tmail'
require 'uuidtools'
$config = configatron.configure_from_yaml(File.expand_path(File.dirname(__FILE__) + "/config/config.yml"))
loop do
Net::POP3.start($config["pop_config"]["server"],
$config["pop_config"]["port"],
$config["pop_config"]["uname"],
$config["pop_config"]["passwd"]) do |pop|
#Get the email from the server
pop.each_mail do |m|
#Create a UUID so we have unique filenames
filename = UUID.random_create
#Parse the email into a format that we may break it down using TMail
fetched_email = TMail::Mail.parse(m.pop)
f = File.new(File.expand_path(File.dirname(__FILE__) + "/tmp/#{filename}.tif"), "w")
f.write(fetched_email.body)
f.close
new_email = TMail::Mail.new
new_email.to = $config["smtp_config"]["to_address"]
new_email.subject = $config["smtp_config"]["subject"]
new_email.date = Time.now
new_email.body = fetched_email.body
Net::SMTP.start($config["smtp_config"]["server"], $config["smtp_config"]["port"]) do |smtpclient|
smtpclient.send_message(new_email.to_s, "[email protected]", $config["smtp_config"]["to_address"])
end
puts 'Sent email @ ' + Time.now.to_s
#m.delete
end
end
sleep $config["pop_config"]["fetch_interval"].to_i
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment