# Mailer behavior...anybody have any more tips to get it worki

**URL:** <https://www.ruby-forum.com/t/mailer-behavior-anybody-have-any-more-tips-to-get-it-worki/71741>\
**Category:** Radiant CMS\
**Created:** [October 11, 2006, 7:15am UTC](https://www.ruby-forum.com/t/mailer-behavior-anybody-have-any-more-tips-to-get-it-worki/71741 "2006-10-11T07:15:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jsmorris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6f9a4e/32.png) [@jsmorris](https://www.ruby-forum.com/u/jsmorris)\
**Post date:** [October 11, 2006, 7:15am UTC](https://www.ruby-forum.com/t/mailer-behavior-anybody-have-any-more-tips-to-get-it-worki/71741/1 "2006-10-11T07:15:46Z")

</div>

I have scoured the list and it seems that several people are having  
issues with the mailer behavior and I am one of them.

I have tried all the suggestions that I found in the mailing list, but  
still it doesn’t work.

I have edited my environment.rb file to remove the ActionMailer from  
being excluded on startup. I have add  
ActionMailer::Base.server\_settings needed for my hosting provider  
(RailsPlayground). I have configured my page, config and email parts.

My form displays correctly, I click send, I don’t see any errors on  
screen or in the production log file but the email never shows up.

Is there any more troubleshooting that I can do to make sure my  
configuration is correct? I guess the next step is to debug the  
behavior, but since I am still a nuby, I find it difficult. I was  
hoping one of the smart people on this list would have an answer.

Any help or guidance would be appreciated.

---

<div class="post-metadata">

**Author:** ![jsmorris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6f9a4e/32.png) [@jsmorris](https://www.ruby-forum.com/u/jsmorris)\
**Post date:** [October 11, 2006, 8:44am UTC](https://www.ruby-forum.com/t/mailer-behavior-anybody-have-any-more-tips-to-get-it-worki/71741/2 "2006-10-11T08:44:00Z")

</div>

Did you setup ActionMailer in config/environments/production.rb?

2006/10/11, jsmorris [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![jsmorris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6f9a4e/32.png) [@jsmorris](https://www.ruby-forum.com/u/jsmorris)\
**Post date:** [October 11, 2006, 10:31pm UTC](https://www.ruby-forum.com/t/mailer-behavior-anybody-have-any-more-tips-to-get-it-worki/71741/3 "2006-10-11T22:31:09Z")

</div>

I did set up ActionMailer in the config/environment.rb file, but not  
in the environments/production.rb file.

My understanding was that the config/environment.rb was for settings  
in all environments and if you wanted different configuration per  
environment, then you used the specific file  
envrionment/production.rb.

Am I wrong in this assumption? But, I will move the ActionMailer  
config to that file and see if I get a different result and post back  
to the list.

Thanks for the help.

---

<div class="post-metadata">

**Author:** ![jsmorris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6f9a4e/32.png) [@jsmorris](https://www.ruby-forum.com/u/jsmorris)\
**Post date:** [October 12, 2006, 4:32pm UTC](https://www.ruby-forum.com/t/mailer-behavior-anybody-have-any-more-tips-to-get-it-worki/71741/4 "2006-10-12T16:32:05Z")

</div>

Well I’m not sure really. Your reasoning is logical, I just followed the  
tutorial in the AWDWR book and it suggested to edit the production.rb  
file,  
and it worked 🙂

2006/10/11, jsmorris [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![jsmorris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6f9a4e/32.png) [@jsmorris](https://www.ruby-forum.com/u/jsmorris)\
**Post date:** [October 17, 2006, 7:19am UTC](https://www.ruby-forum.com/t/mailer-behavior-anybody-have-any-more-tips-to-get-it-worki/71741/5 "2006-10-17T07:19:08Z")

</div>

Still working on trying to get the mailer behavior to work. I tried  
to configure the ActionMailer in both files, but no success. I do,  
however, now get an error message on my page after I try to send the  
mail. The error is

“Error encounter while trying to send email. undefined method  
`deliver\_generic\_mailer’ for ActionMailer::Base:Class”

So, I got my hands dirty and tried to debug the code provided in the  
behavior. It looks like in the send\_mail() method, the author is  
trying to dynamically add a method to the ActionMailer::Base class,  
but I am still too new to ruby to understand this completely.

My confusion is why the error message is saying that the calling  
method is deliver\_generic\_mailer, but the method that the author is  
adding to the ActionMailer::Base is called generic\_mailer. I tried to  
just call this method, but that didn’t work.

After seeing the below code, does it look correct? Can anyone  
describe what the \<\<-CODE CODE syntax is all about? Thanks for  
any help in advance

Here is a snippet of the code

```
  ActionMailer::Base.module_eval( <<-CODE ) unless

```

ActionMailer::Base.respond\_to? ‘generic\_mailer’  
def generic\_mailer(options)  
@recipients = options[:recipients]  
@from = options[:from] || “”  
@cc = options[:cc] || “”  
@bcc = options[:bcc] || “”  
@subject = options[:subject] || “”  
@headers = options[:headers] || {}  
@charset = options[:charset] || “utf-8”  
if options.has\_key? :html\_body  
part “text/html” do |a|  
a.body = options[:html\_body] || “”  
end  
end  
if options.has\_key? :plain\_body  
part “text/plain” do |p|  
p.body = options[:plain\_body] || “”  
end  
end  
end  
CODE  
# Now deliver mail using our new generic\_mail method  
ActionMailer::Base.deliver\_generic\_mailer(  
:recipients =\> recipients,  
:from =\> from,  
:subject =\> form\_data[:subject] || “Form Mail from  
#{request.host}”,  
:plain\_body =\> plain\_body,  
:html\_body =\> html\_body  
)

---

<div class="post-metadata">

**Author:** ![jsmorris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6f9a4e/32.png) [@jsmorris](https://www.ruby-forum.com/u/jsmorris)\
**Post date:** [October 17, 2006, 7:31am UTC](https://www.ruby-forum.com/t/mailer-behavior-anybody-have-any-more-tips-to-get-it-worki/71741/6 "2006-10-17T07:31:09Z")

</div>

On 17/10/2006, at 2:18 PM, jsmorris wrote:

> trying to dynamically add a method to the ActionMailer::Base class,  
> but I am still too new to ruby to understand this completely.
> 
> My confusion is why the error message is saying that the calling  
> method is deliver\_generic\_mailer, but the method that the author is  
> adding to the ActionMailer::Base is called generic\_mailer. I tried to  
> just call this method, but that didn’t work.

When you want to deliver email with ActionMailer, you have to prefix  
your method with “deliver\_”, e.g. ActionMailer#generic\_mailer  
(instance method) needs to be called with  
ActionMailer::deliver\_generic\_mailer (class method)

the \<\< CODE CODE stuff is a heredoc [1] used to define the  
mailer method to use UNLESS it is already defined. Then the second  
half of the method calls ActionMailer to deliver the email. I had it  
working a few months ago, I’ll try to dig up the code and put the  
setup on the wiki (if i can find some spare some time for radiant ☹ )

Bodhi

[1] [Here document - Wikipedia](http://en.wikipedia.org/wiki/Heredoc)
