发送ip地址和指定文件到某邮箱_Ruby_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > Ruby > 发送ip地址和指定文件到某邮箱

发送ip地址和指定文件到某邮箱

 2012/12/16 17:21:36  clark1231  程序员俱乐部  我要评论(0)
  • 摘要:#!/usr/bin/envruby##ARGV[0]-msg#ARGV[1]-mailto#ARGV[2]-filenamerequire'open-uri'require'rubygems'require'action_mailer'ActionMailer::Base.smtp_settings={:address=>'smtp.163.com',:port=>25,:domain=>'163.com',:user_name=>'xxfromxx@163.com'
  • 标签:文件
#!/usr/bin/env ruby
#
# ARGV[0] - msg
# ARGV[1] - mailto
# ARGV[2] - filename

require 'open-uri'
require 'rubygems'
require 'action_mailer'

ActionMailer::Base.smtp_settings = {
  :address              => 'smtp.163.com',
  :port                 => 25,
  :domain               => '163.com',
  :user_name            => 'xxfromxx@163.com',
  :password             => 'xxxxxxx',
  :authentication       => 'login',
  :enable_starttls_auto => true
}

class Notifer < ActionMailer::Base
  default :from => 'xxfromxx@163.com'

  def mailip(ip, msg, mailto, file)
    attachments["#{file}"] = File.read("#{file}")
    mail :to => mailto, :subject => "#{msg} ip is #{ip}" do |format|
      format.text { render :text => ip}
    end.deliver
  end
end

open("http://checkip.dyn.com") do |f|
  ip = f.read.slice /[0-9]+(\.[0-9]+){3}/
  filename = "mysql-" + Time.now.strftime("%Y-%m-%d").to_s + ".sql.gz"
  Notifer.mailip ip, ARGV[0], ARGV[1] || 'xxtoxx@163.com', ARGV[2] || filename
end
?

?

发表评论
用户名: 匿名