Last active
December 18, 2015 12:09
-
-
Save DianthuDia/5780849 to your computer and use it in GitHub Desktop.
This file contains 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
#!/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