Skip to content

Instantly share code, notes, and snippets.

@tansengming
Created April 24, 2009 15:14
Show Gist options
  • Star 32 You must be signed in to star a gist
  • Fork 20 You must be signed in to fork a gist
  • Save tansengming/101141 to your computer and use it in GitHub Desktop.
Save tansengming/101141 to your computer and use it in GitHub Desktop.
Rails Console Actionmailer test
# Copy and paste this to the rails console to test your email settings
class MyMailer < ActionMailer::Base
def test_email
@recipients = "someone@somewhere.com"
@from = "must_be_same_as_smpt_account_login@gmail.com"
@subject = "test from the Rails Console"
@body = "This is a test email"
end
end
MyMailer::deliver_test_email
# if all goes well you should see a lot text scrolling by
# Copied with love from http://lists.radiantcms.org/pipermail/radiant/2007-February/003394.html
# btw for info on how to get rails working with Gmail SMTP go to http://robertbousquet.com/articles/using-gmail-smtp-with-actionmailer
@fatihpense
Copy link

in rails3.1.1 console, i managed to send by MyMailer.test_email().deliver

@ByScripts
Copy link

In Rails 3.2, worked with this :

class TestMailer < ActionMailer::Base

  default :from => "me@mysite.com"

  def welcome_email
    mail(:to => "other@elsewhere.com", :subject => "Test mail", :body => "Test mail body")
  end
end

TestMailer.welcome_email.deliver

@jackson-sandland
Copy link

Works phantastic. Rails 4

@michon
Copy link

michon commented Dec 15, 2014

like a charm for me.
Va de pinga

@cbilgili
Copy link

Thank you @tansengming and @ByScripts

@peterept
Copy link

peterept commented Mar 2, 2015

thanks

@wellington1993
Copy link

Thanks

@chucai
Copy link

chucai commented Jan 26, 2016

Thanks! It's work for me in Rails 4.2 .

@neohunter
Copy link

what happen if credentials are invalid? some error is raiseD?

@jasonperrone
Copy link

Thanks dude, this helped me.

@blaskovicz
Copy link

In rails 5, I did SomeMailer::some_method(Thing.first, Otherthing.last).deliver via the console.

@racl101
Copy link

racl101 commented Nov 24, 2016

@ByScripts thanks for your example. Helped me out very much. Works on Rails 4.2.0

@jumph4x
Copy link

jumph4x commented Aug 2, 2017

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment