Action Mailer not working

Forums > Book - Chapter 8 > Action Mailer not working

Login to post a new topic

Pages: 1 2

Author Message
codeme
Member since 07 Jul 22:19
0 posts

When going through Chapter 8 I have the first part of the section done for the blog, but I seem to be getting stuck on the sendmail portion of the Newsletter
This is the error I am getting when I click send for Newsletter:
NoMethodError in NewslettersController#sendmails
You have a nil object when you didn’t expect it!
The error occurred while evaluating nil.subject
RAILS_ROOT: script/../config/..
Application Trace | Framework Trace | Full Trace
app/models/notifier.rb:17:in `newsletter’
app/controllers/newsletters_controller.rb:61:in `sendmails’
app/controllers/newsletters_controller.rb:60:in `each’
app/controllers/newsletters_controller.rb:60:in `sendmails’
I have even tried running the code from the book and it gives me the same error.
I am not sure if the SMTP setup that we did on page 218 still needs to be include or if I even set it up remotely close to what it should be.
If anyone can shed some light it would be much appreciated!

HermanBubbert
Member since 17 Jul 02:33
0 posts

There’s a typo in Notifier#newsletter. The line
body :body => @newsletter.body, :user => user
should be
body :body => newsletter.body, :user => user
newsletter is a local variable, not an instance variable.

Herb Taylor
Member since 05 Aug 04:13
0 posts

My copy of the book did not have that typo and I am still seeing an error when I try to send. Everything else works. I am wondering if the ARMailer installs different on fedora 7 and I have to set some flags.
When I originally ran the migration I did not see the same output as the book – AddArMailer header. I repeated everything with a new name to instantiate a new table (scoopletter instead of newsletter) and got the same result.
Here is my message:
uninitialized constant ActionMailer::ARMailer
RAILS_ROOT: script/../config/..
Application Trace | Framework Trace | Full Trace
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:263:in `load_missing_constant’
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:452:in `const_missing’
app/models/notifier.rb:1
app/controllers/scoopletters_controller.rb:64:in `sendmails’
app/controllers/scoopletters_controller.rb:63:in `each’
app/controllers/scoopletters_controller.rb:63:in `sendmails’

kevox
Member since 11 Jul 11:49
0 posts

Yeah, I’m having pretty much similar problems.
When I tried from my version of the site, I got the ‘uninitialized constant’ error, but when I ran the site from Alan’s Chapter 8 code (using my database.yml), I got the ‘nil object’ error.

kevox
Member since 11 Jul 11:49
0 posts

OK, I got mine to work by using this
ActionMailer::Base.delivery_method = :activerecord
instead of
config.action_mailer.delivery_method = :activerecord
in my /config/environments/development.rb
I gathered this from here:
http://seattlerb.rubyforge.org/ar_mailer/classes/ActionMailer/ARMailer.html

kevox
Member since 11 Jul 11:49
0 posts

Now I’m getting a SQL error when I try to run the command ar_sendmail from the command line as described on page 244 or the e-book.
The error I’m getting is this:
Unhandled exception Mysql::Error: #42S22Unknown column ‘created_on’ in ‘where clause’: SELECT * FROM emails WHERE (last_send_attempt > 0 and created_on < ‘2007-07-29 16:48:22’) (ActiveRecord::StatementInvalid):
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract_adapter.rb:128:in `log’
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/mysql_adapter.rb:243:in `execute’
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/mysql_adapter.rb:399:in `select’
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `select_all’
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:427:in `find_by_sql’
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:997:in `find_every’
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:418:in `find’
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:504:in `destroy_all’
/usr/local/lib/ruby/gems/1.8/gems/ar_mailer-1.3.1/lib/action_mailer/ar_sendmail.rb:398:in `cleanup’
/usr/local/lib/ruby/gems/1.8/gems/ar_mailer-1.3.1/lib/action_mailer/ar_sendmail.rb:499:in `run’
/usr/local/lib/ruby/gems/1.8/gems/ar_mailer-1.3.1/lib/action_mailer/ar_sendmail.rb:496:in `loop’
/usr/local/lib/ruby/gems/1.8/gems/ar_mailer-1.3.1/lib/action_mailer/ar_sendmail.rb:496:in `run’
/usr/local/lib/ruby/gems/1.8/gems/ar_mailer-1.3.1/lib/action_mailer/ar_sendmail.rb:340:in `run’
/usr/local/lib/ruby/gems/1.8/gems/ar_mailer-1.3.1/bin/ar_sendmail:5
/usr/local/bin/ar_sendmail:16:in `load’
/usr/local/bin/ar_sendmail:16
#######
The email table doesn’t have a ‘created_on’ field, but somehow the query is trying to do a comparison on it…
Anyone have a solution for this one?

wlockhart
Member since 13 Jul 09:22
0 posts

Hi kevox,
I made the change you suggested and it still doesn’t work for me. Does anyone else have a suggestion as to how I can resolve this issue?
Thanks in advance.
Kind Regards

wlockhart
Member since 13 Jul 09:22
0 posts

Hi Guys,
I got my code to work.
Yes, there is a typo in the download code version of: app/controllers/newsletter_controller.rb (which is not a typo in the code listing on Page 236 of the book).
In the sendmails method change the following line from:
Notifier.deliver_newsletter(user, @newsletter)
to:
Notifier.deliver_newsletter(user, newsletter)
This works with:
ActionMailer::Base.delivery_method = :activerecord
in /config/environments/development.rb
or
config.action_mailer.delivery_method = :activerecord
in /config/environments/development.rb
Thanks for all your direction and guidance.
Regards
Walter

tmkouba
Member since 05 Feb 16:30
0 posts

Here’s what I encountered:
Chapter 8, page 223 – 224, manually testing email creation.
After entering
>> mail = Notifier.deliver_new_comment_notification(comment)
I received the error:
uninitialized constant ActionMailer:ARMailer
At the bottom of config/environment.rb I added:
require ‘action_mailer/ar_mailer’
Stopped & restarted the Rails application (Mongrel server) (this step is critical! every time you modify a config file, you must restart the app before the changes will be applied).
Everything works fine now.
Hope this helps.
Terri

u196598
Member since 10 Mar 19:08
0 posts

ar_mailer plugin still does nto work for me after following book’s and above’s instructions.
I am using gmail SMTP server to send out email from my application. I am following the instructions from following link and everything is fine. I can send out email whenever a new comment is added.


http://www.railsforum.com/viewtopic.php?pid=55521


When trying to build newsletter feature, I am following book’s instructions. but after these changes, I cannot send out email anymore when adding a new comment. Changes are listed below:
1. install ar_mailer plugin
2. create Email model and emails table:
3. change Notifier class:
#class Notifier < ActionMailer::Base
class Notifier < ActionMailer::ARMailer
...
4. change gmail STMP settings and add ar_mailer in environment.rb file:
#ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.delivery_method = :activerecord
ActionMailer::Base.smtp_settings = {
:address => “smtp.gmail.com”,
:port => 587,
:domain => “mycompany.com”,
:authentication => :plain,
:user_name => “mygmail@gmail.com”,
:password => “fdaspace”
}
require ‘action_mailer/ar_mailer’



After these changes, I restarted the server and tried to add new comments. Everything looks fine without any errors but I cannot send out email anymore.
I checked table emails. whenever adding a new comment, a new record will be added to this table. For example, following is one record data:


id: 9
from: ‘system@railscoders.net’
to: ‘baqig_wang@hotmail.com’
last_send_attempt: 0
mail: ‘From: RailsCoders
To: bwang
Subject: A new comment has been left on your blog
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary=mimepart_47f996ee21728_a782356db0291
—mimepart_47f996ee21728_a782356db0291
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: Quoted-printable
Content-Disposition: inline
Hi bwang,
A new comment has been left on your blog at RailsCoders.net.
The comment was left by ‘Admin’ at =
06 Apr 23:37.
To read the comment, go to http://localhost:3000/users/2/entries/10
Cheers,
The RailsCoders Team
—mimepart_47f996ee21728_a782356db0291
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: Quoted-printable
Content-Disposition: inline
3D"RailsCoders">

Hi bwang,


A new comment has been left on your blog at RailsCoders.


The comment was left by Admi=
n
on 06 Apr 23:37


To read the comment, go to tries/10”>http://localhost:3000/users/2/entries/10


Cheers,

The RailsCoders Team


-mimepart_47f996ee21728_a782356db0291-


Did anybody experience the same problem?


Thanks a lot for your help!


Brian

Pages: 1 2