Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- config/initializers/setup_mail.rb
- --------------------------------------------------------
- ActionMailer::Base.smtp_settings = {
- :address => "smtp.gmail.com",
- :port => 587,
- :domain => "mydomain.com",
- :user_name => "infogmail.com ",
- :password => "+++++",
- :authentication => "plain",
- :enable_starttls_auto => true
- }
- --------------------------------------------------------
- i run : rails g mailer Emailer
- and my App/mailer/emailer.rb
- class Emailer < ActionMailer::Base
- def contact(recipient, subject, message, sent_at = Time.now)
- @subject = subject
- @recipients = recipient
- @from = 'info@gmail.com'
- @sent_on = sent_at
- @body["title"] = 'welcome'
- @body["email"] = 'info@gmail.com'
- @body["message"] = message
- @headers = {}
- end
- end
- --------------------------------------------------------
- after i run : rails g controller Emailer
- and my App/controller/emailer_controller.rb
- class EmailerController < ApplicationController
- def index
- render 'app/views/emailer/index.rhtml'
- end
- def sendmail
- email = @params["email"]
- recipient = email["recipient"]
- subject = email["subject"]
- message = email["message"]
- Emailer.deliver_contact(recipient, subject, message)
- return if request.xhr?
- render :text => 'Message sent successfully'
- end
- end
- --------------------------------------------------------
- app\views\emails\index.rhtml
- <h1>Send Email</h1>
- <%= form_tag :action => 'sendmail', :method => :get %>
- <p><label for="email_subject">Subject</label>:
- <%= text_field 'email', 'subject' %></p>
- <p><label for="email_recipient">Recipient</label>:
- <%= text_field 'email', 'recipient' %></p>
- <p><label for="email_message">Message</label><br/>
- <%= text_area 'email', 'message' %></p>
- <%= submit_tag "Send" %>
- <% end %>
- ----------------------------
- this code not running....why?it is correct?
Add Comment
Please, Sign In to add comment