Forum: Ruby on Rails Action Mailer woes

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Eric S. (Guest)
on 2006-01-30 03:16
(Received via mailing list)
Hi gang,
Im having my first stab at ActionMailer and not having any luck. Perhaps
someone could help me out.
I generated a a mailer called ItemMailer - its purpose is to take some
information that I've already gathered in a ToDo list form and to mail
it out to the person who is nominated for the task

In environment.rb I have;
ActionMailer::Base.server_settings = {
:address => "pop3.nsw.exemail.com.au",
:port => 25,
:authentication => :login,
:user_name => "removed_email_address@domain.invalid",
:password => "wouldntyouliketoknow"
}

I have a Mailer model;
class ItemMailer < ActionMailer::Base
  	def item_assignment( address, title, body )
	  # Email header info MUST be added here
	  @recipients = address
	  @from = "removed_email_address@domain.invalid"
	  @subject = title
	  @body = body
#	  breakpoint 'mailer'
	  # Email body substitutions go here

	end
end

In the controller I have;
...
# Send the Email
@recipient = Person.find(:first, :conditions => ['id =
?',@to_dos.user_id])
@email_address = @recipient.email_address
ItemMailer::create_item_assignment(@email_address, @to_dos.title,
@to_dos.body)
...

I dont need any fancy stuff like variable substitution, just a way to
pop the recipient, subject and body into an email object. When I try to
run this I get to the breakpoint OK so at least part of the controller
code is fine. After the breakpoint nothing happens. the app just chugs
along into the subsequent redirect and no mail is sent. There is nothing
in the development log to point to the problem

Can anyone help?
Kind Regards,
Eric.
Ricky Nelson (Guest)
on 2006-01-30 04:01
(Received via mailing list)
I believe your mistake is that you are trying to send form data but
you are treating it like ActiveRecord data.  It took me a couple of
hours to get my head wrapped around it too.  Try this in your
controller:

> # Send the Email
@email = ItemMailer.create_item_assignment(params
[:whatever_your_form_data_is]) #you didn't post your form so its hard
to tell what variable to use here.
ItemMailer.deliver(@email)
render :action => 'some_action'

then in your model do the following:

> 	end
> end

You see if you're trying to send a form then the data is an array NOT
ActiveRecord.  I hope that helps.

-Ricky
http://www.socketwiz.com/
Eric S. (Guest)
on 2006-01-30 06:47
(Received via mailing list)
Ricky,
Thanks for the response. I'm a step forward and another sideways
I now have;

class ItemMailer < ActionMailer::Base
   	def item_assignment( contact )
	  # Email header info MUST be added here
	  breakpoint 'mailer'
	  @recipients = contact[:address]
	  @from = "removed_email_address@domain.invalid"
	  @subject = contact[:title]
	  @body = contact[:body]
	end
end

And in Controller;
def add_to_dos
@job = Job.find(params[:id])
@to_dos = ToDo.new( params['to_do'])
@to_dos.update_attribute( 'due_on', params[:to_do][:due_on][:date] )
@to_dos.update_attribute('job_id', @job.id)
@to_dos.update_attribute('created_by', '1' )
if @to_dos.save!
   # Log the event
   @j_evt = JobEvent.new(:job_id => @job.id, :user_id => 1,
	:event_type_id => @to_dos.to_do_type_id,
	:title => @to_dos.title, :refer_id =>@to_dos.id )

   if @j_evt.save
	# Send the Email
	@recipient = Person.find(:first, :conditions => ['id =
?',@to_dos.user_id])
	@email_address = @recipient.email_address
	@contact = {:address =>@email_address, :title => @to_dos.title,
:body => @to_dos.body}
	@email = ItemMailer::create_item_assignment(@contact)
	ItemMailer.deliver(@email)
	flash[:notice] = 'Item was successfully created.'
	redirect_to :action => 'job_dashboard', :id => @job
   else
.....
Results In;

454 oops, unable to write pipe and I can't auth (#4.3.0)
Eric S. (Guest)
on 2006-01-30 07:11
(Received via mailing list)
Sorry - should have put the full trace

  Net::SMTPAuthenticationError in Job#add_to_dos

454 oops, unable to write pipe and I can't auth (#4.3.0)

RAILS_ROOT: ./script/../config/..
Application Trace | Framework Trace | Full Trace

d:/ruby/lib/ruby/1.8/net/smtp.rb:586:in `auth_login'
d:/ruby/lib/ruby/1.8/net/smtp.rb:571:in `__send__'
d:/ruby/lib/ruby/1.8/net/smtp.rb:571:in `authenticate'
d:/ruby/lib/ruby/1.8/net/smtp.rb:411:in `do_start'
d:/ruby/lib/ruby/1.8/net/smtp.rb:378:in `start'
d:/ruby/lib/ruby/1.8/net/smtp.rb:316:in `start'
d:/ruby/lib/ruby/gems/1.8/gems/actionmailer-1.1.5/lib/action_mailer/base.rb:436:in
`perform_delivery_smtp'
d:/ruby/lib/ruby/gems/1.8/gems/actionmailer-1.1.5/lib/action_mailer/base.rb:327:in
`send'
d:/ruby/lib/ruby/gems/1.8/gems/actionmailer-1.1.5/lib/action_mailer/base.rb:327:in
`deliver!'
d:/ruby/lib/ruby/gems/1.8/gems/actionmailer-1.1.5/lib/action_mailer/base.rb:254:in
`deliver'
#{RAILS_ROOT}/app/controllers/job_controller.rb:188:in `add_to_dos'


Request

Parameters: {"commit"=>"Save", "to_do"=>{"sub_reference"=>"",
"body"=>"see how they run", "title"=>"Blah Blah Black Sheep",
"attachment"=>"", "user_id"=>"14", "to_do_type_id"=>"5",
"due_on"=>{"date"=>"01/30/2006"}}, "id"=>"1", "todo"=>{"log_item"=>"0",
"send_email"=>"0"}}
Eric S. (Guest)
on 2006-01-30 07:26
(Received via mailing list)
OK - I'm cool - still have a problem, but it is in the ISP
authentication stuff. MAny Thanks for your help.
Cheers,
Eric.
Guest (Guest)
on 2006-06-16 14:38
Eric S. wrote:
> OK - I'm cool - still have a problem, but it is in the ISP
> authentication stuff. MAny Thanks for your help.
> Cheers,
> Eric.



the account you are using is pop3 and not the smtp, so that may be your
problem
This topic is locked and can not be replied to.