“拒绝许可”尝试发送验证邮件时 [英] "Permission denied" when trying to send verification email

查看:525
本文介绍了“拒绝许可”尝试发送验证邮件时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Apache和mod_wsgi在Fedora服务器(Fedora Release 15(Lovelock))上运行一个django网站。最近我尝试使用django注册应用程序(0.7版本)添加注册系统,但是不幸的是,当应用程序尝试向新注册的用户发送验证电子邮件时,我会收到[Errno 13]权限被拒绝。我已经配置了我的项目的设置文件,使用gmail帐户这样发送邮件:

I'm running a django website on a fedora server (Fedora release 15 (Lovelock)) using Apache and mod_wsgi. recently I tried to add a registration system using the django-registration app (version 0.7), but unfortunately I get a "[Errno 13] Permission denied" when the app is trying to send verification email to a newly registered user. I've configured the setting file of my project to send emails using a gmail account this way:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'myemailaddress@gmail.com'
EMAIL_HOST_PASSWORD = 'mypassword'
EMAIL_PORT = 587

当我使用项目的shell手动导入send_mail时,我可以发送电子邮件。
我没有改变任何视图或模型。以下是注册模板文件:

I can send emails when I manually import send_mail while using project's shell. I haven't changed anything in the views or models. here is the registration template file:

{% extends "base.html" %}
{% load i18n %}

{% block content %}
<form method="post" action="/accounts/register/">
  {% csrf_token %}
  {{ form }}
  <input type="submit" value="Register"/>
</form>
{% endblock %}

这里是我得到的错误:

[Errno 13] Permission denied
Request Method: POST
Request URL:    http://myip/accounts/register/
Django Version: 1.3.1
Exception Type: error
Exception Value:    
[Errno 13] Permission denied
Exception Location: /usr/lib64/python2.7/socket.py in create_connection, line 571

这是完整的追溯:


Traceback:
File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "/.../lib/registration/views.py" in register
  148.             new_user = form.save(profile_callback=profile_callback)
File "/.../lib/registration/forms.py" in save
  88.                                                                     send_email = True)
File "/.../lib/registration/models.py" in create_inactive_user
  127.             send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [new_user.email])
File "/usr/lib/python2.7/site-packages/django/core/mail/__init__.py" in send_mail
  61.                         connection=connection).send()
File "/usr/lib/python2.7/site-packages/django/core/mail/message.py" in send
  251.         return self.get_connection(fail_silently).send_messages([self])
File "/usr/lib/python2.7/site-packages/django/core/mail/backends/smtp.py" in send_messages
  79.             new_conn_created = self.open()
File "/usr/lib/python2.7/site-packages/django/core/mail/backends/smtp.py" in open
  42.                                            local_hostname=DNS_NAME.get_fqdn())
File "/usr/lib64/python2.7/smtplib.py" in __init__
  239.             (code, msg) = self.connect(host, port)
File "/usr/lib64/python2.7/smtplib.py" in connect
  295.         self.sock = self._get_socket(host, port, self.timeout)
File "/usr/lib64/python2.7/smtplib.py" in _get_socket
  273.         return socket.create_connection((port, host), timeout)
File "/usr/lib64/python2.7/socket.py" in create_connection
  571.         raise err

Exception Type: error at /accounts/register/
Exception Value: [Errno 13] Permission denied


推荐答案

被SELinux阻止。我会检查这些日志,看看是否拒绝你的许可。您可以在/var/log/audit/audit.log中找到主日志尝试该操作,看看它是否在日志结尾生成新消息。如果是这样,那么是不允许发送电子邮件的SELinux。如果生成拒绝,那么您需要更新您的SELinux策略,可能使用audit2allow。有关如何执行此操作的说明,请参阅 SELinux CentOS Howto 。 CentOS和Fedora足够接近,如果SELinux是否定的行为,那么概述的步骤应该是有效的。如果没有,那么这显然是无关紧要的。

This may be being prevented by SELinux. I would check those logs and see if it's denying you the permission. You can probably find the primary log at /var/log/audit/audit.log Try the action and see if it generates a new message at the end of the log. If so, it's SELinux which is disallowing the email send. If that's generating the denial, then you'll need to update your SELinux policy, probably using audit2allow. For instructions on how to do that, see the SELinux CentOS Howto. CentOS and Fedora are close enough that the steps outlined there should work, if SELinux is what's denying the action. If not, then obviously, this would be irrelevant.

您还可以使用命令 setenforce 0 ,看看问题是否消失。无论是否存在,最好使用 setenforce 1 重新执行强制。

You can also try temporarily disabling SELinux enforcement by using the command setenforce 0 and see if the problem goes away. Whether it does or not, it's a good idea to use setenforce 1 to turn enforcement back on again.

这篇关于“拒绝许可”尝试发送验证邮件时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆