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 => "somebody@somewhere.com.au",
: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 = "accounts@mywebsite.com"
@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.
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:> class ItemMailer < ActionMailer::Base > def item_assignment( contact ) > # Email header info MUST be added here > @recipients = contact[''address''] > @from = "accounts@mywebsite.com" > @subject = contact[''title''] > @body = contact[''body''] > # breakpoint ''mailer'' > # Email body substitutions go here > > end > endYou 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/ On Jan 29, 2006, at 8:14 PM, Eric Sloane wrote:> > 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 => "somebody@somewhere.com.au", > :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 = "accounts@mywebsite.com" > @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. > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060130/e13bef75/attachment.html
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 = "accounts@mywebsite.com"
@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)
Ricky Nelson wrote:> 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:
>
>> class ItemMailer < ActionMailer::Base
>> def item_assignment( contact )
>> # Email header info MUST be added here
>> @recipients = contact[''address'']
>> @from = "accounts@mywebsite.com
>> <mailto:accounts@mywebsite.com>"
>> @subject = contact[''title'']
>> @body = contact[''body'']
>> # breakpoint ''mailer''
>> # Email body substitutions go here
>>
>> 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/
>
>
>
> On Jan 29, 2006, at 8:14 PM, Eric Sloane wrote:
>
>>
>> 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 => "somebody@somewhere.com.au
>> <mailto:somebody@somewhere.com.au>",
>> :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 = "accounts@mywebsite.com
>> <mailto:accounts@mywebsite.com>"
>> @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.
>>
>> _______________________________________________
>> Rails mailing list
>> Rails@lists.rubyonrails.org
>> <mailto:Rails@lists.rubyonrails.org>
>> http://lists.rubyonrails.org/mailman/listinfo/rails
>>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
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 Sloane wrote:> 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 = "accounts@mywebsite.com"
> @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)
>
>
> Ricky Nelson wrote:
>
>> 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:
>>
>>> class ItemMailer < ActionMailer::Base
>>> def item_assignment( contact )
>>> # Email header info MUST be added here
>>> @recipients = contact[''address'']
>>> @from = "accounts@mywebsite.com
>>> <mailto:accounts@mywebsite.com>"
>>> @subject = contact[''title'']
>>> @body = contact[''body'']
>>> # breakpoint ''mailer''
>>> # Email body substitutions go here
>>>
>>> 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/
>>
>>
>>
>> On Jan 29, 2006, at 8:14 PM, Eric Sloane wrote:
>>
>>>
>>> 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 => "somebody@somewhere.com.au
>>> <mailto:somebody@somewhere.com.au>",
>>> :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 = "accounts@mywebsite.com
>>> <mailto:accounts@mywebsite.com>"
>>> @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.
>>>
>>> _______________________________________________
>>> Rails mailing list
>>> Rails@lists.rubyonrails.org
>>> <mailto:Rails@lists.rubyonrails.org>
>>> http://lists.rubyonrails.org/mailman/listinfo/rails
>>>
>>
>>
>>
------------------------------------------------------------------------
>>
>> _______________________________________________
>> Rails mailing list
>> Rails@lists.rubyonrails.org
>> http://lists.rubyonrails.org/mailman/listinfo/rails
OK - I''m cool - still have a problem, but it is in the ISP authentication stuff. MAny Thanks for your help. Cheers, Eric. Eric Sloane wrote:> 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 Sloane wrote: > >> 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 = "accounts@mywebsite.com" >> @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) >> >> >> Ricky Nelson wrote: >> >>> 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: >>> >>>> class ItemMailer < ActionMailer::Base >>>> def item_assignment( contact ) >>>> # Email header info MUST be added here >>>> @recipients = contact[''address''] >>>> @from = "accounts@mywebsite.com >>>> <mailto:accounts@mywebsite.com>" >>>> @subject = contact[''title''] >>>> @body = contact[''body''] >>>> # breakpoint ''mailer'' >>>> # Email body substitutions go here >>>> >>>> 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/ >>> >>> >>> >>> On Jan 29, 2006, at 8:14 PM, Eric Sloane wrote: >>> >>>> >>>> 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 => "somebody@somewhere.com.au >>>> <mailto:somebody@somewhere.com.au>", >>>> :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 = "accounts@mywebsite.com >>>> <mailto:accounts@mywebsite.com>" >>>> @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. >>>> >>>> _______________________________________________ >>>> Rails mailing list >>>> Rails@lists.rubyonrails.org >>>> <mailto:Rails@lists.rubyonrails.org> >>>> http://lists.rubyonrails.org/mailman/listinfo/rails >>>> >>> >>> >>> ------------------------------------------------------------------------ >>> >>> _______________________________________________ >>> Rails mailing list >>> Rails@lists.rubyonrails.org >>> http://lists.rubyonrails.org/mailman/listinfo/rails
Eric Sloane 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 -- Posted via http://www.ruby-forum.com/.