title: Django email: Client does not have permission to send as this sender
body: <p>I am able to send emails via smtplib by using the function provided in this SO answer: <a href="https://stackoverflow.com/a/12424439/614770">https://stackoverflow.com/a/12424439/614770</a></p>
  
  <pre><code>from __future__ import print_function
  
  def send_email(user, pwd, recipient, subject, body):
      import smtplib
  
      FROM = user
      TO = recipient if type(recipient) is list else [recipient]
      SUBJECT = subject
      TEXT = body
  
      # Prepare actual message
      message = """From: %s\nTo: %s\nSubject: %s\n\n%s
      """ % (FROM, ', '.join(TO), SUBJECT, TEXT)
      try:
          server = smtplib.SMTP('smtp.office365.com', 587)
          server.ehlo()
          server.starttls()
          server.login(user, pwd)
          server.sendmail(FROM, TO, message)
          server.close()
          print('Successfully sent the mail')
      except:
          print('Failed to send mail')
  
  
  if __name__ == '__main__':
      send_email(
          'my@email.com', 'password', 'my@email.com', 
          'Test Email', 'Can you see this?')
  </code></pre>
  
  <p>However, I receive the following error when I try to send email via django:</p>
  
  <p><strong>settings.py</strong></p>
  
  <pre><code># Email
  EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
  EMAIL_USE_TLS = True
  EMAIL_HOST = 'smtp.office365.com'
  EMAIL_PORT = 587
  EMAIL_HOST_USER = 'my@email.com'
  EMAIL_HOST_PASSWORD = 'password'
  </code></pre>
  
  <p><strong>Command line</strong></p>
  
  <blockquote>
    <p>$ python manage.py sendtestemail -v 3 my@email.com</p>
    
    <p>Traceback (most recent call last):</p>
    
    <p>File "manage.py", line 22, in  execute_from_command_line(sys.argv)</p>
    
    <p>File "C:\Program Files\Anaconda2\envs\django_env\lib\site-packages\django\core\management__init__.py", line 363, in execute_from_command_line utility.execute()</p>
    
    <p>File "C:\Program Files\Anaconda2\envs\django_env\lib\site-packages\django\core\management__init__.py", line 355, in execute self.fetch_command(subcommand).run_from_argv(self.argv)</p>
    
    <p>File "C:\Program Files\Anaconda2\envs\django_env\lib\site-packages\django\core\management\base.py", line 283, in run_from_argv self.execute(*args, **cmd_options)</p>
    
    <p>File "C:\Program Files\Anaconda2\envs\django_env\lib\site-packages\django\core\management\base.py", line 330, in execute output = self.handle(*args, **options)</p>
    
    <p>File "C:\Program Files\Anaconda2\envs\django_env\lib\site-packages\django\core\management\commands\sendtestemail.py", line 33, in handle recipient_list=kwargs['email'],</p>
    
    <p>File "C:\Program Files\Anaconda2\envs\django_env\lib\site-packages\django\core\mail__init__.py", line 62, in send_mail return mail.send()</p>
    
    <p>File "C:\Program Files\Anaconda2\envs\django_env\lib\site-packages\django\core\mail\message.py", line 348, in send return self.get_connection(fail_silently).send_messages([self])</p>
    
    <p>File "C:\Program Files\Anaconda2\envs\django_env\lib\site-packages\django\core\mail\backends\smtp.py", line 111, in send_messages sent = self._send(message)</p>
    
    <p>File "C:\Program Files\Anaconda2\envs\django_env\lib\site-packages\django\core\mail\backends\smtp.py", line 127, in _send self.connection.sendmail(from_email, recipients, message.as_bytes(linesep='\r\n'))</p>
    
    <p>File "C:\Program Files\Anaconda2\envs\django_env\lib\smtplib.py", line 887, in sendmail raise SMTPDataError(code, resp)</p>
    
    <p>smtplib.SMTPDataError: (550, b'5.7.60 SMTP; Client does not have permissions to send as this sender [CY1PR0501MB1116.namprd05.prod.outlook.com]')</p>
  </blockquote>
  
  <p>Have I misconfigured something in django?</p>