-
-
Save Antiarchitect/143e40aaae463486bfc52b8bbf79e9d3 to your computer and use it in GitHub Desktop.
Send Email From Rails Console
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Simple approach to sending email from the Rails console | |
# Implementation idea courtesy of Steve Klabnik | |
# http://blog.steveklabnik.com/posts/2012-09-09-random-ruby-tricks--class-new | |
# Create the mailer class with a block and assign to a variable | |
mailer = Class.new(ActionMailer::Base) do | |
def example_message | |
mail(to: "[email protected]", from: "[email protected]", subject: "Example Message") do |format| | |
format.text { render text: "Example message body" } | |
end | |
end | |
end | |
# Use the class just as you would a typical mailer | |
mailer.example_message.deliver |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment