ruby发送、接收server-ex2007邮件

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

#Ruby发送、接收server-ex2007邮件
require 'net/smtp'
require 'net/pop'

EXServer = 'server-ex2007.xxx.com.cn' #填写EX2007Server地址

def send_mail(addressees, subject, body, sender, password)
  begin
    if addressees.empty?
      return nil
    else
      addressees = addressees.respond_to?(:to_ary) ? addressees : addressees.to_a
      content = "Content-Type:Text/HTML\r\nDate:#{Time.now}\r\nFrom:#{sender}\r\nTo:#{addressees.join(';')}\r\nSubject:#{subject.to_s}\r\n\r\n#{body}"
      Net::SMTP.start(EXServer) do |i|
        i.auth_login(sender, password)
        i.sendmail(content, sender, addressees)
      end
    end
  rescue => ex
    puts "Error:#{ex}"
  end
end

def read_mail(login, password)
  begin
    Net::POP3.start(EXServer, 110, login, password) do |i|
      if i.mails.empty?
        return nil
      else
        i.each_mail do |m|
          yield(m) if block_given?
        end
      end
    end
  rescue => ex
    puts "Error:#{ex}"
  end
end