title: Can't send email in production
body: <p>I am developing online shop and everything worked fine on local machine.Client add item to cart, enter his credentials click 'Make Order' and than order confirmation should be sent to his email. And it was working fine, even with redis + celery, but since when I've deployed project to server (linode.com), order confirmation doesn't work. Worker took tasks but never execute this. I thought it was due to celery, and I've made decision to make sending email without task manager and queue. But it didn't help.</p>
  <p>I use UFW firewall in the server:</p>
  <pre><code>To                         Action      From
  --                         ------      ----
  22/tcp                     ALLOW       Anywhere                  
  80/tcp                     ALLOW       Anywhere                  
  Anywhere                   ALLOW       96.126.119.66             
  443                        ALLOW       Anywhere                  
  22/tcp (v6)                ALLOW       Anywhere (v6)             
  80/tcp (v6)                ALLOW       Anywhere (v6)             
  443 (v6)                   ALLOW       Anywhere (v6)  
  </code></pre>
  <p>I get error like this:</p>
  <blockquote>
  <p>[Errno 110] Connection timed out</p>
  </blockquote>
  <p>Hope you will help me to understand the issue</p>
  <p>Traceback:</p>
  <pre><code>Environment:
  
  
  Request Method: POST
  Request URL: https://bauerdress.ru/orders/create/
  
  Django Version: 3.1
  Python Version: 3.8.5
  Installed Applications:
  ['django.contrib.admin',
   'django.contrib.auth',
   'django.contrib.contenttypes',
   'django.contrib.sessions',
   'django.contrib.messages',
   'django.contrib.sites',
   'django.contrib.staticfiles',
   'shop.apps.ShopConfig',
   'cart.apps.CartConfig',
   'orders.apps.OrdersConfig',
   'wishlist.apps.WishlistConfig',
   'widget_tweaks',
   'crispy_forms',
   'information.apps.InformationConfig',
   'promotion.apps.PromotionConfig',
   'django_filters',
   'email_sub.apps.EmailSubConfig',
   'django_simple_coupons',
   'ckeditor',
   'flower',
   'allauth',
   'allauth.account',
   'allauth.socialaccount']
  Installed Middleware:
  ['django.middleware.security.SecurityMiddleware',
   'django.contrib.sessions.middleware.SessionMiddleware',
   'django.middleware.common.CommonMiddleware',
   'django.middleware.csrf.CsrfViewMiddleware',
   'django.contrib.auth.middleware.AuthenticationMiddleware',
   'django.contrib.messages.middleware.MessageMiddleware',
   'django.middleware.clickjacking.XFrameOptionsMiddleware']
  
  
  
  Traceback (most recent call last):
    File &quot;/home/kirill/venv/lib/python3.8/site-packages/django/core/handlers/exception.py&quot;, line 47, in inner
      response = get_response(request)
    File &quot;/home/kirill/venv/lib/python3.8/site-packages/django/core/handlers/base.py&quot;, line 179, in _get_response
      response = wrapped_callback(request, *callback_args, **callback_kwargs)
    File &quot;/home/kirill/bauer_dress/orders/views.py&quot;, line 46, in order_create
      order_created(order.id)
    File &quot;/home/kirill/bauer_dress/orders/tasks.py&quot;, line 22, in order_created
      mail_sent = send_mail(subject, None, settings.EMAIL_HOST_USER, [order.email, settings.MAIL], html_message=html)
    File &quot;/home/kirill/venv/lib/python3.8/site-packages/django/core/mail/__init__.py&quot;, line 61, in send_mail
      return mail.send()
    File &quot;/home/kirill/venv/lib/python3.8/site-packages/django/core/mail/message.py&quot;, line 284, in send
      return self.get_connection(fail_silently).send_messages([self])
    File &quot;/home/kirill/venv/lib/python3.8/site-packages/django/core/mail/backends/smtp.py&quot;, line 102, in send_messages
      new_conn_created = self.open()
    File &quot;/home/kirill/venv/lib/python3.8/site-packages/django/core/mail/backends/smtp.py&quot;, line 62, in open
      self.connection = self.connection_class(self.host, self.port, **connection_params)
    File &quot;/usr/lib/python3.8/smtplib.py&quot;, line 253, in __init__
      (code, msg) = self.connect(host, port)
    File &quot;/usr/lib/python3.8/smtplib.py&quot;, line 339, in connect
      self.sock = self._get_socket(host, port, self.timeout)
    File &quot;/usr/lib/python3.8/smtplib.py&quot;, line 308, in _get_socket
      return socket.create_connection((host, port), timeout,
    File &quot;/usr/lib/python3.8/socket.py&quot;, line 808, in create_connection
      raise err
    File &quot;/usr/lib/python3.8/socket.py&quot;, line 796, in create_connection
      sock.connect(sa)
  
  Exception Type: TimeoutError at /orders/create/
  Exception Value: [Errno 110] Connection timed out
  </code></pre>
  <p>views.py</p>
  <pre><code>from django.conf import settings
  from django.shortcuts import render, get_object_or_404
  from django.http import HttpResponse
  from cart.cart import Cart
  from .models import OrderItem, Order
  from .forms import OrderCreateForm
  from shop.models import Product
  from django.contrib.admin.views.decorators import staff_member_required
  from django_simple_coupons.forms import CouponApplyForm
  import weasyprint
  from django.template import loader
  from django.core.mail import send_mail
  from email_sub.models import Subscription
  from django.core.exceptions import ObjectDoesNotExist
  from .tasks import order_created
  
  
  
  
   def order_create(request):
      cart = Cart(request)
      coupon_apply_form = CouponApplyForm()
      if request.method == 'POST':
          form = OrderCreateForm(request.POST)
          if form.is_valid():
              order = form.save(commit=False)
              if cart.coupon:
                  order.coupon = cart.coupon
                  order.discount = cart.coupon.discount.value
              order.save()
              for item in cart:
                  OrderItem.objects.create(
                      order=order,
                      product=item['product'],
                      product_set=item['product_set'],
                      price=item['product_set'].price,
                      quantity=item['quantity'],
                      size = item['product_set'].size_set,
                      color = item['color']
                  )
              try:
                  Subscription.objects.get(email=order.email)
              except ObjectDoesNotExist:
                  Subscription.objects.create(name=order.first_name, surname=order.last_name, email=order.email)
              
              order_created(order.id) # &lt;--- order confirmation email 
              cart.clear()
              if cart.coupon:
                  cart.clear_coupon()
              return render(request, 'orders/order/created.html', {'order': order})
      else:
          form = OrderCreateForm()
      return render(request, 'orders/order/create_v2.html', {
          'cart': cart,
          'form': form,
          'coupon_apply_form': coupon_apply_form})
  </code></pre>
  <p>tasks.py</p>
  <pre><code>def order_created(order_id):
      &quot;&quot;&quot;
      Task for sending mail if order created
      &quot;&quot;&quot;
      order = Order.objects.get(id=order_id)
      subject = 'Заказ #{}'.format(order.id)
      html = loader.render_to_string('orders/order/mail2.html', context={'order': order})
      send_mail = send_mail(subject, None, settings.EMAIL_HOST_USER, [order.email, settings.MAIL], html_message=html)
      return send_mail
  </code></pre>
  <p>settings.py (part of smtp settings)</p>
  <pre><code>#smtp
  EMAIL_USE_TLS = True
  EMAIL_HOST = 'smtp.gmail.com'
  EMAIL_HOST_USER = 'myuser@gmail.com' #real data used in production
  EMAIL_HOST_PASSWORD = '1234'
  EMAIL_PORT = 587
  </code></pre>