# ActionMailer with sendmail any help

**URL:** <https://www.ruby-forum.com/t/actionmailer-with-sendmail-any-help/129080>\
**Category:** Rails\
**Created:** [February 14, 2008, 1:07am UTC](https://www.ruby-forum.com/t/actionmailer-with-sendmail-any-help/129080 "2008-02-14T01:07:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![KTU](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ecae2f/32.png) [@KTU](https://www.ruby-forum.com/u/KTU)\
**Post date:** [February 14, 2008, 1:07am UTC](https://www.ruby-forum.com/t/actionmailer-with-sendmail-any-help/129080/1 "2008-02-14T01:07:37Z")

</div>

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](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] || “removed\_email\_address@domain.invalid”  
@from = options[:from] || “Me [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)”  
@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](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

---

<div class="post-metadata">

**Author:** ![KTU](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ecae2f/32.png) [@KTU](https://www.ruby-forum.com/u/KTU)\
**Post date:** [February 14, 2008, 2:51am UTC](https://www.ruby-forum.com/t/actionmailer-with-sendmail-any-help/129080/2 "2008-02-14T02:51:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![KTU](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ecae2f/32.png) [@KTU](https://www.ruby-forum.com/u/KTU)\
**Post date:** [February 14, 2008, 9:09am UTC](https://www.ruby-forum.com/t/actionmailer-with-sendmail-any-help/129080/3 "2008-02-14T09:09:55Z")

</div>

what i have is this:

# Controller

def generic\_email(options)

@sent\_on = options[:sent\_on] || Time.now  
@recipients = options[:recipients] || “removed\_email\_address@domain.invalid”  
@from = options[:from] || “Me [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)”  
@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](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 “removed\_email\_address@domain.invalid”  
from “removed\_email\_address@domain.invalid”  
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](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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![KTU](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ecae2f/32.png) [@KTU](https://www.ruby-forum.com/u/KTU)\
**Post date:** [February 14, 2008, 10:31am UTC](https://www.ruby-forum.com/t/actionmailer-with-sendmail-any-help/129080/4 "2008-02-14T10:31:40Z")

</div>

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
