title: Sending email with attached file in Django
body: <p>I am trying to send and email in Django forms with attached file, but i cant figure out how to send the file(uploaded by user) without saving it locally. 
  I have my form:</p>
  
  <pre><code>class PrintForm(forms.Form):
      contact_name = forms.CharField(required=True)
      contact_email = forms.EmailField(required=True)
      supervisor = forms.ChoiceField(
          choices=[(str(sup.email), str(sup.name)) for sup in Supervisors.objects.all()]
      )
      file = forms.FileField()
      content = forms.CharField(
          required=True,
          widget=forms.Textarea
      )
  </code></pre>
  
  <p>and my view:</p>
  
  <pre><code>def print(request):
     #  context = dict()
     #  context['printers'] = Printer.objects.all()
     #   return render(request, 'threeD/print.html', context)
  
     if request.method == 'POST':
          form = PrintForm(data=request.POST, request = request)
  
          if form.is_valid():
              contact_name = request.POST.get('contact_name', '')
              contact_email = request.POST.get('contact_email', '')
              form_content = request.POST.get('content', '')
              supervisor = form.cleaned_data['supervisor']
              template = get_template('threeD/email/contact_template_for_printing.txt')
              context = Context({
                  'contact_name': contact_name,
                  'supervisor': supervisor,
                  'contact_email': contact_email,
                  'form_content': form_content,
              })
              content = template.render(context)
              subject = "New message"
  
              try:
                  email = EmailMessage(
                      subject,
                      content,
                      contact_email,
                      [supervisor],
                      headers={'Reply-To': contact_email}
                  )
                  #email.attach(...)
                  email.send()
              except:
                  return "Attachment error"
  
              messages.success(request, "Thank you for your message.")
              return redirect('/index/print/')
  
     else:
              form = PrintForm(request=request)
     context_dict = {}
     context_dict['printers'] = Printer.objects.all()
     context_dict['form'] = form
     return render(request, 'threeD/print.html', context_dict)
  </code></pre>
  
  <p>So in my view, when i am sending an email, is there a way to call <code>email.attach(file)</code> which would attach file to a mail and send it but without locally saving the file? (form and view works fine, without file feature implementation)</p>
  
  <p>EDIT:
  <br> here is HTML code snippet, where i call for the form:</p>
  
  <pre><code> &lt;div class="panel-body"&gt;
          &lt;form role="form" action="" method="post"&gt;
              {% csrf_token %}
              {% load bootstrap %}
                 {{ form|bootstrap }}
  
              &lt;div class="text-center"&gt;
                  &lt;button type="submit" class="btn btn-primary"&gt;&lt;span class="glyphicon glyphicon-send"&gt;&lt;/span&gt;    Send a message&lt;/button&gt;
              &lt;/div&gt;
          &lt;/form&gt;
   &lt;/div&gt;
  </code></pre>
  
  <p>Any help would be very much appreciated. Thanks!</p>