Ask A Question


You’re not receiving notifications from this thread.

sending the simplest of emails? (ruby or RoR)

sweedledee asked in Rails

Am I missing something very basic, what does it take for me to send a simple email with 'hello' to my personal inbox in ruby (or Rails)
in php it's this simple : mail("","My subject",$msg);

I know php has to be running from a server to able to do anything, but what would I need to get the equivalent in ruby (or rails?) from my local computer?

I tried the Rails Guides Action mailer basics only to be rewarded with output in the terminal :(

...or copy and paste the following from
with the following code running in a test_email.rb file and execute with $ruby test_email.rb

require 'net/smtp'

message = < From: Private Person
To: A Test User
Subject: SMTP e-mail test

This is a test e-mail message.

Net::SMTP.start('localhost') do |smtp|
smtp.send_message message, '', ''

Returns this :
/Users/me/.rbenv/versions/2.7.2/lib/ruby/2.7.0/net/smtp.rb:539:in `initialize': Connection refused - connect(2) for "localhost" port 25 (Errno::ECONNREFUSED)

(Can that only run from a server?)


It's looking for an SMTP server running on your machine on port 25. You'd have to run something like postfix to do that.

Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 83,453+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.