Skip to content

Instantly share code, notes, and snippets.

@DianthuDia
Last active December 18, 2015 12:09
Show Gist options
  • Save DianthuDia/5780849 to your computer and use it in GitHub Desktop.
Save DianthuDia/5780849 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# coding: utf-8
require 'net/pop'
require 'net/smtp'
AUTH = {
from: '', to: %w[],
pop: {host: '', ssl: true, user: '', pass: ''},
smtp: {host: '', port: 587, user: '', pass: ''},
}
_smtp = Net::SMTP.new AUTH[:smtp][:host], AUTH[:smtp][:port]
_smtp.enable_ssl if AUTH[:smtp][:port] == Net::SMTP.default_ssl_port
_smtp.enable_starttls if AUTH[:smtp][:port] == Net::SMTP.default_submission_port
_smtp.start(`hostname`.strip, AUTH[:smtp][:user], AUTH[:smtp][:pass]) do |smtp|
_pop = Net::POP3.new AUTH[:pop][:host]
_pop.enable_ssl if AUTH[:pop][:ssl]
_pop.start(AUTH[:pop][:user], AUTH[:pop][:pass]) do |pop|
pop.each do |m|
begin
smtp.open_message_stream(AUTH[:from], AUTH[:to]){|f| m.pop{|c| f << c} }
m.delete
rescue => e
puts e # send failed
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment