"Permission denied" when trying to send confirmation email

I am running a django site on a fedora server (Fedora 15 release (Lovelock)) using Apache and mod_wsgi. I recently tried to add a registration system using the django registration application (version 0.7), but unfortunately, I get permission "[Errno 13] Permission denied" when the application tries to send an email confirmation to a new registered user. I configured my project settings file to send emails using a gmail account as follows:

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 

I can send emails when I manually import send_mail when using the project shell. I have not 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 %} 

and here is the error I get:

 [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 

this is the full trace:

  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
+6
source share
3 answers

This can be prevented by SELinux. I would check these logs and see if you are being denied permission. You can probably find the primary log in /var/log/audit/audit.log. Try the action and see if it generates a new message at the end of the log. If so, this is SELinux, which prohibits sending emails. If this causes a failure, you will need to update the SELinux policy, possibly using audit2allow. For instructions on how to do this, see the SELinux CentOS manual . CentOS and Fedora are close enough that the steps described here should work if SELinux is what negates the action. If not, then obviously this does not matter.

You can also try temporarily disabling SELinux enforcement using the setenforce 0 command and see if the problem setenforce 0 . Whether it is or not, it is recommended that you use setenforce 1 to enable enforcement again.

+9
source

This may be an I / O error. Do you make any print statements or write material to a file in your presentation? If so, you can get permissions. Please check and reply.

+1
source

These are the lines you should add to your settings.py:

 EMAIL_HOST = 'smtp.webfaction.com' EMAIL_HOST_USER = '<mailbox>' EMAIL_HOST_PASSWORD = '<password>' DEFAULT_FROM_EMAIL = '<address>' SERVER_EMAIL = '<address>' 

delete @ domain.com in EMAIL_HOST_USER so that it will just be myemailaddress

0
source

Source: https://habr.com/ru/post/900176/


All Articles