# Action Mailer woes

**URL:** <https://www.ruby-forum.com/t/action-mailer-woes/98658>\
**Category:** Rails\
**Created:** [January 30, 2006, 2:16am UTC](https://www.ruby-forum.com/t/action-mailer-woes/98658 "2006-01-30T02:16:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![soderic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8baadc/32.png) [@soderic](https://www.ruby-forum.com/u/soderic)\
**Post date:** [January 30, 2006, 2:16am UTC](https://www.ruby-forum.com/t/action-mailer-woes/98658/1 "2006-01-30T02:16:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![soderic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8baadc/32.png) [@soderic](https://www.ruby-forum.com/u/soderic)\
**Post date:** [January 30, 2006, 3:01am UTC](https://www.ruby-forum.com/t/action-mailer-woes/98658/2 "2006-01-30T03:01:30Z")

</div>

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/](http://www.socketwiz.com/)

---

<div class="post-metadata">

**Author:** ![soderic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8baadc/32.png) [@soderic](https://www.ruby-forum.com/u/soderic)\
**Post date:** [January 30, 2006, 5:47am UTC](https://www.ruby-forum.com/t/action-mailer-woes/98658/3 "2006-01-30T05:47:27Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![soderic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8baadc/32.png) [@soderic](https://www.ruby-forum.com/u/soderic)\
**Post date:** [January 30, 2006, 6:26am UTC](https://www.ruby-forum.com/t/action-mailer-woes/98658/4 "2006-01-30T06:26:51Z")

</div>

OK - I’m cool - still have a problem, but it is in the ISP  
authentication stuff. MAny Thanks for your help.  
Cheers,  
Eric.

---

<div class="post-metadata">

**Author:** ![soderic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8baadc/32.png) [@soderic](https://www.ruby-forum.com/u/soderic)\
**Post date:** [January 30, 2006, 6:11am UTC](https://www.ruby-forum.com/t/action-mailer-woes/98658/5 "2006-01-30T06:11:38Z")

</div>

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”}}

---

<div class="post-metadata">

**Author:** ![soderic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8baadc/32.png) [@soderic](https://www.ruby-forum.com/u/soderic)\
**Post date:** [June 16, 2006, 12:38pm UTC](https://www.ruby-forum.com/t/action-mailer-woes/98658/6 "2006-06-16T12:38:25Z")

</div>

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
