title: Django send_mail through gmail very slow
body: <p>When I try send through ./manage.py shell it takes several minutes to send a single email. When I try to send a user verification email after a form submission in a browser the browser times out with a 504, but the email is eventually sent. What could be going on?</p>
  
  <p>settings.py</p>
  
  <pre><code>...
  EMAIL_HOST = 'smtp.gmail.com'                                                   
  EMAIL_HOST_USER = 'myemail@gmail.com'                                      
  EMAIL_PORT = 587                                                                
  EMAIL_USE_TLS = True                                                            
  DEFAULT_FROM_EMAIL = EMAIL_HOST_USER                                            
  EMAIL_HOST_PASSWORD = os.environ.get('PASSWORD')   
  ...
  </code></pre>
  
  <p>views.py</p>
  
  <pre><code>class SignUpView(CreateView):                                                   
      model = User                                                                
      template_name = 'eventMap/register.html'                                    
      form_class = RegistrationForm                                               
      success_url="/"                                                             
  
      def form_valid(self, form):                                                 
                  form.save()                                                     
                  username = form.cleaned_data['username']                        
                  email = form.cleaned_data['email']                              
                  salt = hashlib.sha1(str(random.random())).hexdigest()[:5]          
                  activation_key = hashlib.sha1(salt+email).hexdigest()           
                  key_expires = datetime.datetime.today() + datetime.timedelta(2) 
  
                  #Get user by username                                           
                  user=User.objects.get(username=username)                        
  
                  # Create and save user profile                                  
                  new_profile = UserProfile(user=user, activation_key=activation_key,
                          key_expires=key_expires)                                
                  new_profile.save()                                              
  
                  # Send email with activation key                                
                  email_subject = 'Account confirmation'                          
                  email_body = "Hey %s, thanks for signing up. To activate your account, click this link within \
                  48hours http://mywebsite.com/accounts/confirm/%s" % (username, activation_key)
  
                  send_mail(email_subject, email_body, 'myemail@gmail.com',  
                          ['mytestemail@gmail.com'], fail_silently=False)   
  
                  return super(SignUpView, self).form_valid(form) 
  </code></pre>
  
  <p>I came across this post about something similar but the logs don't mention anything about an unqualified hostname etc
  /var/log/mail.log</p>
  
  <pre><code>Jul 27 16:26:04 django postfix/qmgr[5975]: CAF7C1226F2: from=&lt;&gt;, size=3063, nrcpt=1 (queue active)
  Jul 27 16:26:34 django postfix/smtp[12874]: connect to example.com[2606:2800:220:1:248:1893:25c8:1946]:25: Connection timed out
  Jul 27 16:27:04 django postfix/smtp[12874]: connect to example.com[93.184.216.34]:25: Connection timed out
  Jul 27 16:27:04 django postfix/smtp[12874]: CAF7C1226F2: to=&lt;myemail@example.com&gt;, relay=none, delay=368178, delays=368118/0.02/60/0, dsn=4.4.1, status=deferred (connect to example.com[93.184.216.34]:25: Connection timed out)
  </code></pre>