# SMTP SMS Reminder Script

**URL:** <https://www.ruby-forum.com/t/smtp-sms-reminder-script/193423>\
**Category:** Ruby\
**Created:** [August 17, 2010, 3:04pm UTC](https://www.ruby-forum.com/t/smtp-sms-reminder-script/193423 "2010-08-17T15:04:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![humandictionary](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/65b543/32.png) [@humandictionary](https://www.ruby-forum.com/u/humandictionary)\
**Post date:** [August 17, 2010, 3:04pm UTC](https://www.ruby-forum.com/t/smtp-sms-reminder-script/193423/1 "2010-08-17T15:04:16Z")

</div>

require ‘net/smtp’  
puts “How many times do you want to bomb 'em?”  
x = gets.to\_i  
puts “What’s your gmail account?”  
username = gets  
puts “Password for that account?”  
password=gets  
message = \<\<MESSAGE\_END  
From: Private P.  
To: A Test User  
Subject: Test  
This is a test e-mail message.  
MESSAGE\_END  
Times\_Sent = gets.to\_i  
Net::SMTP.start(‘[smtp.gmail.com](http://smtp.gmail.com)’, 587, ‘[gmail.com](http://gmail.com)’,  
username, password, :plain) do |smtp|  
smtp.send\_message message  
‘@gmail.com’  
‘@txt.att.net’  
end  
while Times\_Sent \< x  
Times\_Sent = Times\_Sent + 1  
end  
puts “#{Times\_Sent} sent successfully!”

This isn’t wokring for some reason, it’s supposed to send sms messages  
to remind people of stuff, you can send them many times, but the  
authentacation doesn’t work. Help?

---

<div class="post-metadata">

**Author:** ![humandictionary](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/65b543/32.png) [@humandictionary](https://www.ruby-forum.com/u/humandictionary)\
**Post date:** [August 17, 2010, 3:38pm UTC](https://www.ruby-forum.com/t/smtp-sms-reminder-script/193423/2 "2010-08-17T15:38:40Z")

</div>

Hd Pwnz0r wrote:

> username = gets  
> …  
> password=gets  
> …

Probably it’s the newline on the end of the username and password. Try

username = gets.chomp  
password = gets.chomp

---

<div class="post-metadata">

**Author:** ![humandictionary](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/65b543/32.png) [@humandictionary](https://www.ruby-forum.com/u/humandictionary)\
**Post date:** [August 17, 2010, 3:43pm UTC](https://www.ruby-forum.com/t/smtp-sms-reminder-script/193423/3 "2010-08-17T15:43:48Z")

</div>

Brian C. wrote:

> Hd Pwnz0r wrote:
> 
> > username = gets  
> > …  
> > password=gets  
> > …
> 
> Probably it’s the newline on the end of the username and password. Try
> 
> username = gets.chomp  
> password = gets.chomp

I’ve tried that previously, the script just sits there until I interrupt  
it.

---

<div class="post-metadata">

**Author:** ![humandictionary](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/65b543/32.png) [@humandictionary](https://www.ruby-forum.com/u/humandictionary)\
**Post date:** [August 17, 2010, 4:31pm UTC](https://www.ruby-forum.com/t/smtp-sms-reminder-script/193423/4 "2010-08-17T16:31:40Z")

</div>

Hd Pwnz0r wrote:

> Brian C. wrote:
> 
> > Hd Pwnz0r wrote:
> > 
> > > username = gets  
> > > …  
> > > password=gets  
> > > …
> > 
> > Probably it’s the newline on the end of the username and password. Try
> > 
> > username = gets.chomp  
> > password = gets.chomp
> 
> I’ve tried that previously, the script just sits there until I interrupt  
> it.

Sure. So you have another bug. To be sure, try typing a wrong password  
and see if it’s rejected.

Try adding some STDERR.puts “…” lines to see how far you’re getting.

I note some strange things in your script:

Net::SMTP.start(‘[smtp.gmail.com](http://smtp.gmail.com)’, 587, ‘[gmail.com](http://gmail.com)’,  
username, password, :plain) do |smtp|  
smtp.send\_message message  
‘@gmail.com’ #\<\< this line does nothing  
‘@txt.att.net’ #\<\< this line does nothing  
end

and:

while Times\_Sent \< x  
Times\_Sent = Times\_Sent + 1 # This just loops until Times\_sent == x  
end

I suggest you start with the simplest possible script - which sends one  
E-mail - before making it more complex. Google for “ruby Net::SMTP  
gmail” to find some working examples.

---

<div class="post-metadata">

**Author:** ![humandictionary](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/65b543/32.png) [@humandictionary](https://www.ruby-forum.com/u/humandictionary)\
**Post date:** [August 19, 2010, 1:33am UTC](https://www.ruby-forum.com/t/smtp-sms-reminder-script/193423/5 "2010-08-19T01:33:54Z")

</div>

require ‘net/smtp’  
require ‘smtp-tls’  
require ‘rubygems’  
puts “How many times do you want to bomb 'em?”  
x = gets.to\_i  
puts “What’s your gmail account? (Without @gmail.com)”  
username = gets.chomp  
from = username  
puts “Password for that account?”  
password=gets.chomp  
puts “What’s the number you want to bomb?”  
victim = gets.chomp  
to = victim  
puts “What do you want the message bombed to be?”  
body = gets.chomp  
message = \<\<MESSAGE\_END  
From: you #{username}@gmail.com  
To: Victim #{victim}@txt.att.net  
#{body}  
MESSAGE\_END  
smtp = Net::SMTP.new ‘[smtp.gmail.com](http://smtp.gmail.com)’, 587  
smtp.enable\_starttls  
smtp.start(Socket.gethostname,username,password,:login) do |server|  
server.send\_message message, #{from}@gmail.com, #{to}@txt.att.net  
end  
while Times\_Sent \< x  
Times\_Sent = Times\_Sent + 1  
end  
puts “#{Times\_Sent} sent successfully!”

Here’s the updated version. Weird error, I’ve never seen it before.

Error:

sms.rb:24:in `block in <main>': wrong number of arguments (1 for 2) (ArgumentError) from C:/Ruby191/lib/ruby/1.9.1/net/smtp.rb:526:in `start’  
from sms.rb:23:in `’

---

<div class="post-metadata">

**Author:** ![humandictionary](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/65b543/32.png) [@humandictionary](https://www.ruby-forum.com/u/humandictionary)\
**Post date:** [August 17, 2010, 7:03pm UTC](https://www.ruby-forum.com/t/smtp-sms-reminder-script/193423/6 "2010-08-17T19:03:08Z")

</div>

Brian C. wrote:

> Hd Pwnz0r wrote:
> 
> > Brian C. wrote:
> > 
> > > Hd Pwnz0r wrote:
> > > 
> > > > username = gets  
> > > > …  
> > > > password=gets  
> > > > …
> > > 
> > > Probably it’s the newline on the end of the username and password. Try
> > > 
> > > username = gets.chomp  
> > > password = gets.chomp
> > 
> > I’ve tried that previously, the script just sits there until I interrupt  
> > it.
> 
> Sure. So you have another bug. To be sure, try typing a wrong password  
> and see if it’s rejected.
> 
> Try adding some STDERR.puts “…” lines to see how far you’re getting.
> 
> I note some strange things in your script:
> 
> Net::SMTP.start(‘[smtp.gmail.com](http://smtp.gmail.com)’, 587, ‘[gmail.com](http://gmail.com)’,  
> username, password, :plain) do |smtp|  
> smtp.send\_message message  
> ‘@gmail.com’ #\<\< this line does nothing  
> ‘@txt.att.net’ #\<\< this line does nothing  
> end
> 
> and:
> 
> while Times\_Sent \< x  
> Times\_Sent = Times\_Sent + 1 # This just loops until Times\_sent == x  
> end
> 
> I suggest you start with the simplest possible script - which sends one  
> E-mail - before making it more complex. Google for “ruby Net::SMTP  
> gmail” to find some working examples.

stderr:

/usr/lib/ruby/1.8/net/smtp.rb:551:in `initialize': getaddrinfo: Servname not supported for ai_socktype (SocketError) from /usr/lib/ruby/1.8/net/smtp.rb:551:in `open’  
from /usr/lib/ruby/1.8/net/smtp.rb:551:in `do_start' from /usr/lib/ruby/1.8/timeout.rb:62:in `timeout’  
from /usr/lib/ruby/1.8/timeout.rb:93:in `timeout' from /usr/lib/ruby/1.8/net/smtp.rb:551:in `do\_start’  
from /usr/lib/ruby/1.8/net/smtp.rb:525:in `start' from /usr/lib/ruby/1.8/net/smtp.rb:463:in `start’  
from prog.rb:15

There’s the stderr, and I’ll check into that thanks. It still gets the  
output but there’s a socketerror.
