Skip to content

Instantly share code, notes, and snippets.

@jonahoffline
Created September 2, 2013 21:05
Show Gist options
  • Save jonahoffline/6417275 to your computer and use it in GitHub Desktop.
Save jonahoffline/6417275 to your computer and use it in GitHub Desktop.
Send SMS through gmail. Extracted from an irc-bot plugin I made. Currently works with Claro, AT&T and T-Mobile. Feel free to add more carriers :)
require 'mail'
module SpamBitch
module Phone
def self.carriers
{ claro: 'vtexto.com', att: 'txt.att.net', tmobile: 'sms.tmobile.net' }
end
def self.send_sms(telephone, msg, carrier)
options = {
:address => 'smtp.gmail.com',
:port => 587,
:domain => 'gmail.com',
:authentication => 'plain',
:user_name => ENV['EMAIL'],
:password => ENV['PASSWORD'],
:enable_starttls_auto => true
}
Mail.defaults do
delivery_method :smtp, options
end
mail = Mail.new do
from "#{ENV['EMAIL']}"
to "#{telephone}@#{SpamBitch::Phone.carriers[carrier]}"
subject 'SMS from SpamBitch'
body " #{msg}"
end
mail.deliver!
end
def self.sms(carrier='')
gateway = carrier.empty? ? carriers[random_carrier] : carriers[carrier]
"#{telephone.gsub(/-/, '')}@#{gateway}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment