Skip to content
Permalink
master
Go to file
 
 
Cannot retrieve contributors at this time
executable file 79 lines (65 sloc) 1.81 KB
#!/usr/bin/env ruby
# frozen_string_literal: true
# sms.rb
# Author: William Woodruff
# ------------------------
# Sends SMS/MMS messages using SMTP gateways provided by cellular companies.
# Supports most large (US) cellular providers, reads messages from stdin.
# Reads SMTP credentials and information from ~/.smsrc.
# ------------------------
# This code is licensed by William Woodruff under the MIT License.
# http://opensource.org/licenses/MIT
require "yaml"
begin
require "mail"
rescue LoadError
abort("Fatal: The 'mail' gem is required.")
end
smsrc = File.expand_path("~/.smsrc")
abort("Fatal: No ~/.smsrc found.") unless File.file?(smsrc)
conf = YAML.load_file(smsrc)
opts = {
address: conf["smtp"],
port: 587,
user_name: conf["email"],
password: conf["password"],
authentication: conf["auth"],
enable_starttls_auto: true,
}
# prefer mms where available
providers = [
"%<number>s@email.uscc.net",
"%<number>s@message.alltel.com",
"%<number>s@message.ting.com",
"%<number>s@messaging.sprintpcs.com",
"%<number>s@mobile.celloneusa.com",
"%<number>s@msg.telus.com",
"%<number>s@paging.acswireless.com",
"%<number>s@pcs.rogers.com",
"%<number>s@qwestmp.com",
"%<number>s@tmomail.net",
"%<number>s@mms.att.net",
"%<number>s@vzwpix.com",
"%<number>s@text.republicwireless.com",
"%<number>s@mms.cricketwireless.net",
"%<number>s@vmobl.com",
]
number = ARGV.shift
abort("Usage: #{$PROGRAM_NAME} <phone number>") if number.nil? || number !~ /\d{9,10}/
Mail.eager_autoload!
Mail.defaults do
delivery_method :smtp, opts
end
message = STDIN.read
addresses = providers.map { |p| p % { number: number } }
threads = []
addresses.each do |address|
threads << Thread.new do
Mail.new do
from conf["email"]
to address
body message
end.deliver!
end
end
threads.each(&:join)
You can’t perform that action at this time.