sending emails
This is a wiki article created by HostingRails users. Please login or signup to make edits.
I’m having trouble sending emails correctly.
my controller looks like
def generic_email(options)
@sent_on = options[:sent_on] || Time.now
@recipients = options[:recipients] || "me@MYDOMAIN.com"
@from = options[:from] || "ElJefe <contact@MYDOMAIN.com>"
@cc = options[:cc] || ""
@bcc = options[:bcc] || ""
@subject = options[:subject] || "Test Email"
@body = options[:body] || {}
@headers = options[:headers] || {}
@charset = options[:charset] || "utf-8"
end
def test
options=Hash.new
self.generic_email(options)
end
I’ve defined a test.rhtml view. and my environment.rb is configured as
ActionMailer::Base.delivery_method = :sendmail
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.default_charset = "utf-8"
UserMailer.default_url_options[:host] = 'localhost:3000'
UserMailer.mail_from = 'webmaster@localhost'
When I issue the command Contact::deliver_test I get the usual response, the description of the object created.
#<TMail::Mail port=#<TMail::StringPort:id=0x..fdb9f687e> bodyport=#<TMail::StringPort:id=0x..fdb9f3520>>
log file
# Logfile created on Fri Apr 06 20:47:31 -0500 2007 by logger.rb/1.5.2.9
Sent mail:
Date: Fri, 6 Apr 2007 20:47:39 -0500^M
From: contact@withyourmind.com^M
To: admin@withyourmind.com^M
Subject: Test Email^M
Mime-Version: 1.0^M
Content-Type: text/plain; charset=utf-8^M
^M
this is the body
unfortunately I didn’t ever receive any messages by doing this. I’m guessing this has to do with the fact that Rails could possibly queue the emails before sending them out.
ar_sendmail fails with this:
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:477:in `const_missing': uninitialized constant CGI::Session::ActiveRecordStore (NameError)
from /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/session_management.rb:22:in `const_get'
from /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/session_management.rb:22:in `session_store='
from ./config/../vendor/rails/railties/lib/initializer.rb:328:in `send'
from ./config/../vendor/rails/railties/lib/initializer.rb:328:in `initialize_framework_settings'
from ./config/../vendor/rails/railties/lib/initializer.rb:327:in `each'
from ./config/../vendor/rails/railties/lib/initializer.rb:327:in `initialize_framework_settings'
from ./config/../vendor/rails/railties/lib/initializer.rb:324:in `each'
from ./config/../vendor/rails/railties/lib/initializer.rb:324:in `initialize_framework_settings'
... 12 levels...
from /usr/local/lib/ruby/gems/1.8/gems/ar_mailer-1.1.0/lib/action_mailer/ar_sendmail.rb:279:in `run'
from /usr/local/lib/ruby/gems/1.8/gems/ar_mailer-1.1.0/bin/ar_sendmail:5
from /usr/local/bin/ar_sendmail:16:in `load'
from /usr/local/bin/ar_sendmail:16
any ideas where to start?
-----------------
Hey there - please ask this kind of question in the "Rails Coding" or "Deployment Troubleshooting" forums --- off the top of my head I'd first ask if you have AR sessions enabled in your environment.rb? But - please copy and paste this to another forum topic and we'll discuss there. thanks.
Adamwest
William