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 "recipient@mail.com"
  6. from "you@yourdomain.com"
  7. subject "Hello World"
  8. body address
  9. end
  10. end
  11.  
  12. # TLS settings are for gmail, not needed for other mail hosts.
  13. Notifier.delivery_method = :smtp
  14. Notifier.smtp_settings = {
  15. :tls => true,
  16. :enable_starttls_auto => true,
  17. :address => "smtp.gmail.com",
  18. :port => 587,
  19. :domain => "yourdomain.com",
  20. :user_name => "you@yourdomain.com",
  21. :password => "12345",
  22. :authentication => :plain
  23. }
  24.  
  25. Notifier.deliver_email("recipient@mail.com")

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.