SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast satishtalim's Avatar
    Join Date
    Jun 2005
    Location
    Pune, India
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Sending mail problem

    I wanted to send an email from my desktop using a simple Ruby program. I installed 1st SMTP Server - an easy to use SMTP mail relay server. It is used for relaying your email messages to its destinations quickly and easily.

    Then the program I wrote was (based on RFC 821) -
    Code:
    require 'socket'
    t = TCPSocket.new('localhost', 25)
    puts t.gets
    t.puts 'HELO Welcome from Ruby'
    puts t.gets
    t.puts 'MAIL FROM:<abc@gmail.com>'
    puts t.gets
    t.puts 'RCPT TO:<abc@gmail.com>'
    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:

    Code:
    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 <CRLF>.<CRLF>
    
    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.
    Free Ruby Study Notes
    Blog on Java, Ruby programming, Chess and Making $$$ online

  2. #2
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was able to sucessfully use:
    Code:
      require 'net/smtp'
      Net::SMTP.start('server.name') { |m| m.send_message msg, email, email }
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  3. #3
    SitePoint Enthusiast satishtalim's Avatar
    Join Date
    Jun 2005
    Location
    Pune, India
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I too am able to use the Net::SMTP class without any problem. However, I also wanted to try out the TCPSocket class to do the same.

    Quote Originally Posted by sweatje
    I was able to sucessfully use:
    Code:
      require 'net/smtp'
      Net::SMTP.start('server.name') { |m| m.send_message msg, email, email }
    Free Ruby Study Notes
    Blog on Java, Ruby programming, Chess and Making $$$ online

  4. #4
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Perhaps you can look into the code of the SMTP class and see where you are going wrong.
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  5. #5
    SitePoint Enthusiast satishtalim's Avatar
    Join Date
    Jun 2005
    Location
    Pune, India
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, you got me wrong. Using the Net::SMTP class I can send off an email without any problem. However, the problem came when I was trying to do something similar using TCPSocket class.

    Or maybe you mean I should look into the smtp.rb source file? That's a good idea, infact.

    Quote Originally Posted by sweatje
    Perhaps you can look into the code of the SMTP class and see where you are going wrong.
    Free Ruby Study Notes
    Blog on Java, Ruby programming, Chess and Making $$$ online

  6. #6
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by satishtalim
    Or maybe you mean I should look into the smtp.rb source file? That's a good idea, infact.
    Yes, that is what I meant
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •