From: Francis Cianfrocca Date: 2006-07-30T22:00:50+09:00 Subject: Re: TCPSocket and RFC 821 This line: t.puts "\r\n.\r\n" puts one more linefeed on the output than you perhaps intended, which may account for the nil in your output. The QUIT command may be causing the localhost server-connection to close before your process has a chance to read the input. Meaning that the EINVAL error is generated by the gets call you make right after sending QUIT. Try the same program with a mail server located on a different machine and see if you get a different result. After sending QUIT on an SMTP connection, you don't really need to read the server response. (Unless you suspect for some reason the server will send an interesting error-response to your QUIT, which I've never seen in many years of working with SMTP servers.) On 7/30/06, Satish Talim wrote: > I wanted to send an email from my desktop using a simple Ruby program. > I installed 1st SMTP Server > (http://www.emailarms.com/products/1st_smtp.html) - an easy to use > SMTP mail relay server. It is used for relaying your email messages to > its destinations quickly and easily. For this server, I need to use > localhost and port 25 on my PC. > > Then the program I wrote was (based on RFC 821) - > > require 'socket' > t = TCPSocket.new('localhost', 25) > puts t.gets > t.puts 'HELO Welcome from Ruby' > puts t.gets > t.puts 'MAIL FROM:' > puts t.gets > t.puts 'RCPT TO:' > puts t.gets > t.puts 'DATA' > puts t.gets > t.puts 'Test Email from Ruby' > t.puts "\r\n.\r\n" > puts t.gets > t.puts 'QUIT' > puts t.gets > t.close > > However, while running the program, I get an error as follows: > > 220 Welcome to the 1st SMTP Server > > 250 Hello Welcome from Ruby > > 250 abc@gmail.com Address Okay > > 250 abc@gmail.com Address Okay > > 354 Start mail input; end with . > > nil > email.rb:15:in `write': Invalid argument (Errno::EINVAL) > from email.rb:15:in `puts' > from email.rb:15 > >Exit code: 1 > > I am unable to figure out what the problem is. All help appreciated. > >