Setting proxy in Django
<p>I am trying to send email is using django.core.mail.send_mail(). However I am getting the following error when I try submit the form.</p>

<p>Here is the error I am getting:</p>

<pre><code>Request Method: POST
Request URL: http://127.0.0.1:8000/contact/

Django Version: 1.8.10
Python Version: 2.7.6
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'newsletter',
 'Contact')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.middleware.security.SecurityMiddleware')


Traceback:
File "/home/sumit/Desktop/Home/Django/local/lib/python2.7/site-packages/Django-1.8.10-py2.7.egg/django/core/handlers/base.py" in get_response
  132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/sumit/Desktop/Home/Django/src/Contact/views.py" in contact
  25.           fail_silently=False
File "/home/sumit/Desktop/Home/Django/local/lib/python2.7/site-packages/Django-1.8.10-py2.7.egg/django/core/mail/__init__.py" in send_mail
  62.     return mail.send()
File "/home/sumit/Desktop/Home/Django/local/lib/python2.7/site-packages/Django-1.8.10-py2.7.egg/django/core/mail/message.py" in send
  303.         return self.get_connection(fail_silently).send_messages([self])
File "/home/sumit/Desktop/Home/Django/local/lib/python2.7/site-packages/Django-1.8.10-py2.7.egg/django/core/mail/backends/smtp.py" in send_messages
  100.             new_conn_created = self.open()
File "/home/sumit/Desktop/Home/Django/local/lib/python2.7/site-packages/Django-1.8.10-py2.7.egg/django/core/mail/backends/smtp.py" in open
  58.             self.connection = connection_class(self.host, self.port, **connection_params)
File "/usr/lib/python2.7/smtplib.py" in __init__
  256.             (code, msg) = self.connect(host, port)
File "/usr/lib/python2.7/smtplib.py" in connect
  316.         self.sock = self._get_socket(host, port, self.timeout)
File "/usr/lib/python2.7/smtplib.py" in _get_socket
  291.         return socket.create_connection((host, port), timeout)
File "/usr/lib/python2.7/socket.py" in create_connection
  553.     for res in getaddrinfo(host, port, 0, SOCK_STREAM):

Exception Type: gaierror at /contact/
Exception Value: [Errno -2] Name or service not known
</code></pre>

<p>This is my <strong>views.py</strong> file.</p>

<pre><code>from django.shortcuts import render
from .forms import ContactUsForm
from django.core.mail import send_mail
from django.conf import settings

def contact(request):
    form = ContactUsForm(request.POST or None)
    context = {
        "title" : "Contact", 
        "form" : form,
    }
    if form.is_valid():
        form_email = form.cleaned_data.get("email")
        form_full_name = form.cleaned_data.get("full_name")

        subject = "Sent via django"
        from_email = settings.EMAIL_HOST_USER
        to_email = [form_email]
        contact_message = "Thank you %s " %(form_full_name)

        send_mail(subject, 
            contact_message, 
            from_email, 
            to_email,
            fail_silently=False
            )
        context = {
            "title" : "Thank you for your feedback ! "
        }
        form.save()
    return render(request, "contact.html", context)
</code></pre>

<p><strong>forms.py:</strong></p>

<pre><code>from django import forms
from .models import ContactUs

class ContactUsForm(forms.ModelForm):
    class Meta:
        model = ContactUs
        fields = ["full_name", "email", "message"]
</code></pre>

<p><strong>models.py</strong></p>

<pre><code>from django.db import models

# Create your models here.
class ContactUs(models.Model):
    full_name = models.CharField(max_length=120, blank=True)
    email = models.EmailField()
    message = models.CharField(max_length=100, blank=True)
    timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
    updated = models.DateTimeField(auto_now=True, auto_now_add=False)

    def __unicode__(self):
        return self.email
</code></pre>

<p>I have set proxy variables in my terminal using:</p>

<pre><code>export https_proxy="https://username:password@myproxy:myport"
export http_proxy="http://username:password@myproxy:myport"
export socks_proxy="socks://username:password@myproxy:myport"
export ftp_proxy="ftp://username:password@myproxy:myport"
</code></pre>

<p>How do I fix this error? Please help.</p>