ActionMailer Gmail Example


/ Published in: Ruby
Save to your folder(s)

Simple example for using ActionMailer with Gmail (or other hosts if you remove the TLS settings).


Copy this code and paste it in your HTML
  1. require "action_mailer"
  2.  
  3. class Notifier < ActionMailer::Base
  4. def email(address)
  5. recipients "[email protected]"
  6. subject "Hello World"
  7. body address
  8. end
  9. end
  10.  
  11. # TLS settings are for gmail, not needed for other mail hosts.
  12. Notifier.delivery_method = :smtp
  13. Notifier.smtp_settings = {
  14. :tls => true,
  15. :enable_starttls_auto => true,
  16. :address => "smtp.gmail.com",
  17. :port => 587,
  18. :domain => "yourdomain.com",
  19. :user_name => "[email protected]",
  20. :password => "12345",
  21. :authentication => :plain
  22. }
  23.  
  24. Notifier.deliver_email("[email protected]")

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.