[英]Sendmail working in Linux Terminal, not in Rails 3
I'm running Ubuntu 10.04 with Rails 3.2.2. 我正在使用Rails 3.2.2运行Ubuntu 10.04。
I just installed and configured sendmail. 我刚刚安装并配置了sendmail。 When mail is sent through terminal it worked perfectly .
当邮件通过终端发送时,它可以正常工作 。
But when i try to call it through Rails, no success . 但是当我尝试通过Rails调用它时,没有成功 。
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: 我在开发中,在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: 我已经设置了一个actionmailer以及相应的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 我尝试过的事情-尝试在生产模式下运行-将sendmail可执行文件更改为777-尝试删除优先级设置-使用Rails服务器而不是nginx运行它
I hope someone can help me, thanks in advance! 希望有人能帮助我,在此先感谢! (email.com is just a replacement, i use a valid domain)
(email.com只是一个替代品,我使用的是有效域)
EDIT: sadiqxs answer does indeed solve the problem when I try to execute the mail function through rails console. 编辑:当我尝试通过Rails控制台执行邮件功能时,sadiqxs的回答确实可以解决问题。 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.
奇怪的是,这似乎仅在nginx中发生。 When I stop nginx, and start rails server, then it works.
当我停止nginx并启动Rails服务器时,它就可以工作了。 But when I when nginx is the server, it doesnt send any mail.
但是当我当nginx是服务器时,它不发送任何邮件。
我想你需要打电话
UserMailer.alert_mail(site).deliver
sadiqxs solution is the part of the answer to my question. sadiqxs解决方案是我问题的答案的一部分。 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: 我使用ls -ld / var / spool / mqueue-client /来查看目录受smmsp组的限制:
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: 所以我将nobody用户(从错误SYSERR(nobody))添加到了smmsp组:
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”的主要组更改为/ etc / psswd文件的115(smmsp),并看到以下设置:
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.
我知道这不是最好的解决方案,但是我真的不知道该如何给其他人提供访问权限,因为它需要特定的GID。 I hope someone else here does.
我希望其他人也可以。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.