All threads / sending the simplest of emails? (ruby or RoR)

Ask A Question

Notifications

You’re not receiving notifications from this thread.

sending the simplest of emails? (ruby or RoR)

sweedledee asked in Rails

(newbe)
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("[email protected]","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 https://www.tutorialspoint.com/ruby/ruby_sending_email.htm
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.
MESSAGE_END

Net::SMTP.start('localhost') do |smtp|
smtp.send_message message, '[email protected]', '[email protected]'
end

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

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

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

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

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2021 GoRails, LLC. All rights reserved.