Skip to content

Instantly share code, notes, and snippets.

@caok
Created November 13, 2012 13:39
Show Gist options
  • Save caok/4065807 to your computer and use it in GitHub Desktop.
Save caok/4065807 to your computer and use it in GitHub Desktop.
mailip
#!/usr/bin/env ruby
#
# ARGV[0] - msg
# ARGV[1] - mailto
require 'open-uri'
require 'rubygems'
require 'action_mailer'
ActionMailer::Base.smtp_settings = {
:address => 'smtp.163.com',
:port => 25,
:domain => '163.com',
:user_name => '[email protected]',
:password => 'xxxx',
:authentication => 'login',
:enable_starttls_auto => true
}
class Notifer < ActionMailer::Base
default :from => '[email protected]'
def mailip(ip, msg, mailto)
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}/
Notifer.mailip ip, ARGV[0], ARGV[1] || '[email protected]'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment