KTU
February 14, 2008, 1:07am
1
hi
any good examples how to set up email (sendmail especially) with ruby
on rails.
I have tried several examples from the net but no success.
I tried these instructions:
http://wiki.rubyonrails.org/rails/pages/HowToSendEmailsWithActionMailer
and what I have now in controller
def generic_email(options)
@sent_on = options[:sent_on] || Time.now
@recipients = options[:recipients] || “[email protected] ”
@from = options[:from] || “Me [email protected] ”
@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
when I run test http://localhost:3000/test
nothing happens … no email … cant see anything on the log etc
on environment.rb file i have
ActionMailer::Base.delivery_method = :sendmail
ActionMailer::Base.perform_deliveries = true
KTU
February 14, 2008, 2:51am
2
On 14 Feb 2008, at 00:06, KTU wrote:
hi
any good examples how to set up email (sendmail especially) with ruby
on rails.
Is your sendmail where rails expects it to be (usr/sbin/sendmail)? You
can of course override this setting, but that is where it will look by
default.
Also, in order for an email to actually be send you need to call
SomeMailer.deliver_generic_email (or create_generic_email and then
send that).
Lastly it sounds like you’ve defined generic_email on your controller,
which obviously can’t work. It needs to be defined on a subclass of
ActionMailer::Base (script/generate mailer will generate you the right
files)
Fred
KTU
February 14, 2008, 9:09am
3
what i have is this:
Controller
def generic_email(options)
@sent_on = options[:sent_on] || Time.now
@recipients = options[:recipients] || “[email protected] ”
@from = options[:from] || “Me [email protected] ”
@cc = options[:cc] || “”
@bcc = options[:bcc] || “”
@subject = options[:subject] || “Test Email”
@body = options[:body] || {}
@headers = options[:headers] || {}
@charset = options[:charset] || “utf-8”
UserMailer.deliver_signup_thanks()
redirect_to :action => ‘main’
end
def test
options=Hash.new
self.generic_email(options)
end
now I try to run URL this http://localhost:3000/test ie. test should
make that Hash and call self.generic_emai
which calls UserMailer.deliver_signup_thanks() and this file is on my
models directory notifier.rb and it has this:
def signup_thanks()
Email header info MUST be added here
recipients “[email protected] ”
from “[email protected] ”
subject “Test 123”
Email body substitutions go here
body :user=> user
body “test123”
end
So I just try to send pre-defined email to myself but it does not seem
to work. Yes sendmail is in /usr/sbin directory.
Strange is that I cant see any logs or anything…
when I run http://localhost:3000/test
i see only this page but nothing goes to server logs and I dont see
any email logs anywhere …
NameError in ImitemsController#test
uninitialized constant ImitemsController::UserMailer
RAILS_ROOT: /usr/local/webhome/mdm
Application Trace | Framework Trace | Full Trace
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/
active_support/dependencies.rb:478:in const_missing' app/controllers/imitems_controller.rb:16:in
generic_email’
app/controllers/imitems_controller.rb:22:in `test’
On Feb 14, 3:50 am, Frederick C. [email protected]
KTU
February 14, 2008, 10:31am
4
i got it to work i needed to add these on config/environments/
development.rb
ActionMailer::Base.delivery_method = :sendmail
ActionMailer::Base.sendmail_settings = {
:location => ‘/usr/sbin/sendmail’,
:arguments => ‘-i -t’
}
#ActionMailer::Base .template_root = “mailer/templates”
mailer will look for rhtml templates in that path
example: “mailer/templates/my_mailer/signup_mail.rhtml”
ActionMailer::Base.perform_deliveries = true # the “deliver_*” methods
are available
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.default_charset = “utf-8”
ActionMailer::Base.default_content_type = “text/html” # default: “text/
plain”
ActionMailer::Base.default_mime_version = “1.0”
ActionMailer::Base.default_implicit_parts_order = [ “text/html”, “text/
plain”]
and config/environment.rb these
ActionMailer::Base.delivery_method = :sendmail
#ActionMailer::Base .perform_deliveries = true
ActionMailer::Base.raise_delivery_errors = true