small medium large xlarge

Generic-user-small
15 Sep 2009, 15:51
Barry Mccall (4 posts)

Hello Everyone:

using Instant rails and I am trying to send an email in rails locally through the virtual apache server that instant rails starts up for me. I have not been successful here is some of the code.

environment.rb

ActionMailer::Base.delivery_method = :sendmail 
  #| :sendmail | :test
 
  ActionMailer::Base.smtp_settings = 
  {
   :address => 'localhost',
   :port => 25,
   :domain => "127.0.0.1:3000",
   #:authentication => :plain,
   #:user_name => "username",
   #:password => "password",
   
  }

ActionMailer::Base.default_content_type = "text/html"
ActionMailer::Base.default_charset = "utf-8"
ActionMailer::Base.perform_deliveries = true

sendcomment.html.erb

<h1>Send Email</h1>
<% form_tag :action => 'sendmail' do %>

	<p><label for="emailer_subject">Subject</label>:
	<%= text_field 'emailer', 'subject' %></p>
	<p><label for="emailer_recipient">Recipient</label>:
	<%= text_field 'emailer', 'recipient' %></p>
	<p><label for="emailer_message">Message</label><br/>
	<%= text_field 'emailer', 'message' %></p>
	<%= submit_tag "Send" %>
<% end %>

emailer_controller.rb

def sendmail
      email = params[:emailer]        #<= this does work I can get the object but I dont know how to get the info out of it
      message = params[:message]      #this code is not working either the text message isnt shouwing up
      subject = params[:subject]      #not working
      recipient = params[:recipient]  #not working
      
      email = Emailer.create_comments(recipient, subject, message)
      Emailer.deliver(email)
      return if request.xhr?
	  flash[:notice] =  params[:message]     #this code is not working either the text message isnt showing up
	  redirect_to(:action => "comments" ) 

   end

emailer.rb

  def send(recipient, subject, message )
      @subject = subject
      @recipients = recipient
      @from = 'no-reply@yourdomain.com'
      @sent_on = Time.now
	  
	  @body["title"] = 'Comments'
  	  @body["email"] = '127.0.0.1:3000/comments'
   	  @body["message"] = message
      @headers = {}
   end

sendmail.html.erb

email to <%= @recipient %> with a title 

<%= @title %>
and following is the message:
<%= @message %>

Thanks

To put it short it is not working I got most of this from a tutorial online: http://www.tutorialspoint.com/ruby-on-rails-2.1/rails-send-emails.htm. I chose to do this because I had fairly different needs than the example in the book (I dont have any orders to confirm I just want to send an email.) Can someone shed some light on this for me?

Thanks

28555da_pragsmall
03 Dec 2009, 00:26
David Wilbur (49 posts)

barry,

ActionMailer::Base.smtp_settings = 
  {
   :address => 'localhost',
   :port => 25,
   :domain => "127.0.0.1:3000",
   #:authentication => :plain,
   #:user_name => "username",
   #:password => "password",

  }

is only meaningful to smtp and should be taken out. the working environment.rb that i have for sendmail only has the line:

config.action_mailer.delivery_method = :sendmail

and nothing else relative to action_mailer.

You must be logged in to comment