rails 3 email question: how to get /usr/sbin/sendmail executable file? - ruby-on-rails

in rails 3 sendmail_settings, there is a option :location which represent the location of the sendmail executable (Defaults to /usr/sbin/sendmail). In my ubuntu OS machine, there is no such file under /usr/sbin, how can I get /usr/sbin/sendmail executable then?

If you want to override options for the :sendmail delivery method then you can use sendmail_settings. You can override these setting in your environment file.
config.action_mailer.sendmail_settings = {
:location => '/usr/sbin/sendmail',
:arguments => '-i -t'
}

sudo apt-get install sendmail-bin. You should have done a search using a package manager. It's ubuntu.. Also it looks like gzipped executables can be found all over the web.

Related

RuntimeError (Location of wkhtmltopdf unknown)

I am trying to use pdf generator in my rails 2.3app. It is working fine
in my local machine and pdf is generating. In my production server (nginix) it is not working and shows the error:
"wkhtmltopdf RuntimeError (Location of wkhtmltopdf unknown)"
In the config/initializers/wicked_pdf.rb.example file I have mentioned the path to the binary exe file as:
WickedPdf.config = {
:wkhtmltopdf => '/opt/wkhtmltopdf-amd64',
:layout => 'pdf.html'
:header => {:html => {:template=> 'layouts/pdf_header.html'}}
}
And in the opt folder there is wkhtmltopdf-amd64 binary exe file.
:wkhtmltopdf => '/opt/wkhtmltopdf-amd64',
This is your system opt folder, check whether this folder has permission to execute the binary.
Alternatively change the location of wkhtmltopdf into your rails application by extracting it to /path/to/rails_app/bin
and then change your initializer to :wkhtmltopdf => Rails.root.join('bin', 'wkhtmltopdf-amd64').to_s
can we replace the path with installed gem at gemset?
At terminal just check 'which wkhtmltopdf' is installed in our app gemset path.Then replace the path your wkhtmltopdf initializer with that.

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: alert#email.com>, <To: chris#email.com>, <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: "alert#email.com"
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.
I think you need to call
UserMailer.alert_mail(site).deliver
sadiqxs solution is the part of the answer to my question. It fixes the problem that I was calling the function wrong. But it was still not sending email for me. After a while i manage to get it working.
One of the things I found out is that there was actually another mail log which I did oversee:
/var/log/mail.log.1
It showed me the following error:
sendmail[4453]: NOQUEUE: SYSERR(nobody): can not chdir(/var/spool/mqueue-client/): Permission denied
I used ls -ld /var/spool/mqueue-client/ to see that the directory is restricted by the smmsp group:
drwxrws--- 2 smmsp smmsp 4096 2013-01-12 17:51 /var/spool/mqueue-client/
So I added the nobody user (from the error SYSERR(nobody)) to the smmsp group:
usermod -a -G smmsp nobody
I tested again, and it doesn't work yet. After checking the log I got the same error. To be sure I rebooted my server and now the error message changed a little bit:
NOQUEUE: SYSERR(nobody): can not write to queue directory /var/spool/mqueue-client/ (RunAsGid=65534, required=115): Permission denied
After searching and trying useless stuff for a while i decide to change the primary group of nobody to 115 (smmsp) the /etc/psswd file and saw the following settings:
nobody:x:65534:65534:nobody:/nonexistent:/bin/sh
to
nobody:x:65534:115:nobody:/nonexistent:/bin/sh
This solved my problem and it's sending mails now. I understand that this is not the best solution, but I don't really know how else I would give nobody access, since it's requiring the specific GID. I hope someone else here does.

How to set path to PDFkit (gem can't find wkhtmltopdf)?

I'm running Rails on Windows and installed wkhtmltopdf(path - C:\Users\User\local\bin). I'm trying to configure it using documentation - https://github.com/pdfkit/pdfkit#configuration. But it gives me errors about path.
I create pdfkit.rb file in initializers folder and wrote this:
PDFKit.configure do |config|
config.wkhtmltopdf = "C:Users/User/local/bin"
config.default_options = {
:page_size => 'Legal',
:print_media_type => true
}
end
but it gives me error
No wkhtmltopdf executable found at C:Users/User/local/bin
>> Please install wkhtmltopdf - https://github.com/jdpace/PDFKit/wiki/Installing-WKHTMLTOPDF
You need to specify the whole executable path and put a slash after C:
The path should look like: C:/Users/User/local/bin/wkhtmltopdf.exe consider also that you may use backslash \ instead of slash / in Windows

Setting wkhtmltopdf path in rails

I'm having this error when I try to use wicked_pdf:
irb: No such file or directory - which wkhtmltopdf
NoMethodError: You have a nil object when you didn't expect it!
The error occurred while evaluating nil.chomp
from C:/Ruby187/lib/ruby/gems/1.8/gems/wicked_pdf-0.7.2/lib/wicked_pdf.r
b:19:in `initialize'
from (irb):2:in `new'
from (irb):2
from :0
I think the path to wkhtmltopdf should be configured. But how?
Provide sth like
:wkhtmltopdf => '/usr/local/bin/wkhtmltopdf', # path to binary
with your render call and make sure, that a wkhtmltopdf binary resides at that path.
(You can get wkhtmltopdf from google code in case you have not installed it yet)
According to the sources, simply add it to your $PATH (the folder containing the binary).
Wkhtmltopdf project can't be found on Google Code any longer. It was moved to http://wkhtmltopdf.org/downloads.html
In my case, I just had to download the OSX binary and it was automatically added to my PATH variable.
Create an initializer: config/initializers/wicked_pdf.rb:
WickedPdf.config = {
:exe_path => "#{ENV['GEM_HOME']}/bin/wkhtmltopdf"
}
:exe_path should hold the path to the wkhtmltopdf binary. For my instance, I used the gem:
gem "wkhtmltopdf-binary"
Which stored the binary in my GEM_HOME, so I could reference a path that wasnt hard coded.

Paperclip + ImageMagick on Windows 7: Image display fails when I add styles to attached_file in model

I'm working with Ruby on rails 2.3.8, NetBeans IDE.
I've installed paperclip and I could show/save images successfully. Now, I've installed ImageMagick-6.6.2-4-Q16(for windows 7, 64bits).
Until that moment, my model looked like this(and worked fine):
has_attached_file :photo
Now, after installing ImageMagick, when I add the :style line it fails:
has_attached_file :photo,
:styles => {:thumb => "100x100#", :small => "150x150>", :large => "400x400>" }
and it throws the following error message when I try to upload an image:
TypeError in ProfilesController#update
backtrace must be Array of String
The only thing I'm doing in the update action of that controller is the following:
#profile.update_attributes(params[:profile])
#profile.update_attribute(:photo, params[:profile][:photo])
I've also installed miniMagick gem(because I read somewhere I had to do it).
What am I missing?
I'll show you what it worked for us:
There is a name conflict with "convert" command. Paperclips tries to run "convert" as is, but this command is already included in the Windows installations as a filesystem converter (FAT to NTFS or something).
If you try to run "convert" from command line, probably will run the mentioned converter instead of imagemagick's "convert"
It depends on the PATH environment variable.
If we set imagemagick's path FIRST in the PATH variable it will resolve this path first, so the windows' command won't be executed.
In order to fix it on our rails application, we added
...
if Sys::Uname.sysname == "Linux"
...
else
....
ENV['PATH'] = Paperclip.options[:command_path] + ";" + ENV['PATH']
end
...
on production.rb
Try to download the paperclip version 2.3.1.1, higher versions failed to me.

Resources