Guest User

Untitled

a guest
Sep 26th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. config/initializers/setup_mail.rb
  2. --------------------------------------------------------
  3. ActionMailer::Base.smtp_settings = {
  4. :address => "smtp.gmail.com",
  5. :port => 587,
  6. :domain => "mydomain.com",
  7. :user_name => "infogmail.com ",
  8. :password => "+++++",
  9. :authentication => "plain",
  10. :enable_starttls_auto => true
  11. }
  12. --------------------------------------------------------
  13. i run : rails g mailer Emailer
  14.  
  15. and my App/mailer/emailer.rb
  16.  
  17.  
  18. class Emailer < ActionMailer::Base
  19. def contact(recipient, subject, message, sent_at = Time.now)
  20. @subject = subject
  21. @recipients = recipient
  22. @from = 'info@gmail.com'
  23. @sent_on = sent_at
  24. @body["title"] = 'welcome'
  25. @body["email"] = 'info@gmail.com'
  26. @body["message"] = message
  27. @headers = {}
  28. end
  29. end
  30. --------------------------------------------------------
  31. after i run : rails g controller Emailer
  32.  
  33. and my App/controller/emailer_controller.rb
  34.  
  35. class EmailerController < ApplicationController
  36. def index
  37. render 'app/views/emailer/index.rhtml'
  38. end
  39. def sendmail
  40. email = @params["email"]
  41. recipient = email["recipient"]
  42. subject = email["subject"]
  43. message = email["message"]
  44. Emailer.deliver_contact(recipient, subject, message)
  45. return if request.xhr?
  46. render :text => 'Message sent successfully'
  47. end
  48. end
  49. --------------------------------------------------------
  50.  
  51. app\views\emails\index.rhtml
  52.  
  53. <h1>Send Email</h1>
  54. <%= form_tag :action => 'sendmail', :method => :get %>
  55. <p><label for="email_subject">Subject</label>:
  56. <%= text_field 'email', 'subject' %></p>
  57. <p><label for="email_recipient">Recipient</label>:
  58. <%= text_field 'email', 'recipient' %></p>
  59. <p><label for="email_message">Message</label><br/>
  60. <%= text_area 'email', 'message' %></p>
  61. <%= submit_tag "Send" %>
  62. <% end %>
  63. ----------------------------
  64.  
  65. this code not running....why?it is correct?
Add Comment
Please, Sign In to add comment