Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sendmail working in Linux Terminal, not in Rails 3

I'm running Ubuntu 10.04 with Rails 3.2.2.

I just installed and configured sendmail. When mail is sent through terminal it worked perfectly.

But when i try to call it through Rails, no success.

Although it doesn't really looks like it's failing though. I get no errors, and see this in my console:

#<Mail::Message:40338240, Multipart: false, Headers: <From: [email protected]>, <To: [email protected]>, <Subject: Hi chris, a testmail too you!>, <Mime-Version: 1.0>, <Content-Type: text/html>, <importance: High>, <X-Priority: 1>> 

I am in development have the following settings in my development.rb:

config.action_mailer.delivery_method = :sendmail
config.action_mailer.sendmail_settings = { 
      :location => '/usr/sbin/sendmail', 
      :arguments => '-i -t' 
  } 
  config.action_mailer.perform_deliveries = true
  config.action_mailer.raise_delivery_errors = true

I have setup an actionmailer, with the corresponding alert_mail.html.erb:

class UserMailer < ActionMailer::Base
  default from: "[email protected]"
  def alert_mail(site)
    @site = site
    @user = site.user
    @url  = "http://example.com/login"
    mail(:to => @user.email_address, :subject => "Hi chris, a testmail too you!", :importance => "High", 'X-Priority' => '1')
  end
end

And this is what I call:

UserMailer.alert_mail(site)

Could it be something with permissions?

Things i've tried - Tried running in production mode - chmod'd the sendmail executables to 777 - Tried removing the priority settings - Running it with rails server instead of nginx

I hope someone can help me, thanks in advance! (email.com is just a replacement, i use a valid domain)

EDIT: sadiqxs answer does indeed solve the problem when I try to execute the mail function through rails console. But it still doesn't work when it is supposed to, through my browser. Strange thing is, this seems to be happening in nginx only. When I stop nginx, and start rails server, then it works. But when I when nginx is the server, it doesnt send any mail.

like image 701
Chris Avatar asked Dec 07 '25 06:12

Chris


1 Answers

I think you need to call

 UserMailer.alert_mail(site).deliver
like image 159
Mohammad Sadiq Shaikh Avatar answered Dec 09 '25 20:12

Mohammad Sadiq Shaikh