Class: Vtext

Inherits:
Object
  • Object
show all
Defined in:
lib/vtext.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Vtext

Creates a new Vtext object. config is a hash that has the following keys:

config = { "cell_num" => "5551234567899", 
           "username" => String,
           "password" => String,
           "server" => String,
           "port" => String,
         }


21
22
23
24
25
26
27
28
29
# File 'lib/vtext.rb', line 21

def initialize(config)
    @config = { "server" => "smtp.gmail.com",
                "port" => "587",
                "username" => "",
                "password" => "",
                "cell_num" => "",
              }
    @config.merge!(config)
end

Instance Method Details

#send(text) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/vtext.rb', line 31

def send(text)
    mail = TMail::Mail.new

    mail.to = "#{@config['cell_num']}@vtext.com"
    mail.from = "#{@config['username']}@gmail.com"
    mail.date = Time.now
    mail.mime_version = '1.0'
    mail.body = text

    smtp = Net::SMTP.new(@config['server'], @config['port'])
    smtp.enable_starttls

    smtp.start(Socket.gethostname, @config['username'], @config['password'], :login) do |server|
        server.send_message(mail.to_s, mail.from, mail.to)
    end
end