Ruby send mail with smtp

Posted by songdogtech on Stack Overflow See other posts from Stack Overflow or by songdogtech
Published on 2010-04-03T03:50:21Z Indexed on 2010/04/03 3:53 UTC
Read the original article Hit count: 441

Filed under:
|
|
|
|

I'm trying to send simple email via Ruby (no rails) on OS X, with XCode (which installs Ruby.) But I'm running into a problem with my smtp server which requires the email client to check mail before sending as a form of authentication. So with the script below I get an error: 500 Unrecognized command (Net::SMTPAuthenticationError).

How can I get Ruby to authenticate with the smtp server in a "POP" fashion before I can send mail? Not download mail; I only want to send, but I have to check mail before I send. POP3 is not available at the smtp server. And I want to not have to install any other Ruby pieces and stay with using net/smtp, if at all possible.

require 'net/smtp'

message = <<MESSAGE_END
From: A Test Sender <[email protected]>
To: A Test User <[email protected]>
Subject: e-mail test

This is a test e-mail message.
MESSAGE_END

Net::SMTP.start('mail.domain.com', 
                25, 
                'localhost', 
                '[email protected]', 'password', :plain)

© Stack Overflow or respective owner

Related posts about ruby

Related posts about os