Ruby send mail with smtp
- by songdogtech
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)