title: Sending email using python script from an Azure server
body: <p>Using a python script, I am trying to send an email.
  The mail part of the script looks like -</p>
  
  <pre><code>import smtplib
  sender = 'abc.xyz@company.com'
  receiver = 'abc.xyz@company.com'
  message = """From: From Person &lt;abc.xyz@company.com&gt;
  To: To Person &lt;abc.xyz@company.com&gt;
  Subject: Inbound Folder Check - Alert
  Unchanged even after an hour, please check
  """
  smtpObj = smtplib.SMTP('smtp.office365.com',587)
  smtpObj.starttls()
  smtpObj.login('def@company.onmicrosoft.com','Password')
  smtpObj.sendmail(sender, receiver, message)
  </code></pre>
  
  <p>The error that I am getting is -</p>
  
  <blockquote>
    <p>raise SMTPDataError(code, resp) smtplib.SMTPDataError: (554, b'5.2.0
    STOREDRV.Submission.Exception:SendAsDeniedE
    xception.MapiExceptionSendAsDenied; Failed to process message due to a
    permanent exception with message Cannot submit message. ...,
    20.52176:140FCC8414001010640 10000, 20.50032:140FCC848417101069010000, 0.35180:0A006586, 255.23226:6E010000,
    255.27962:0A000000, 255.27962:0E000000, 255.31418:0A00EB87, 16.55847:69000000, 1
    7.43559:0000000090010000000000000D00000000000000, 20.52176:140FCC84140010100A00F 736, 20.50032:140FCC84841710100A00F836, 0.35180:8C010000, 255.23226:40000730, 25
    5.27962:32000000, 255.17082:DC040000, 0.27745:9A010000, 4.21921:DC040000, 255.27 962:FA000000, 255.1494:0A00070E, 0.37692:01000100, 0.44092:01000100, 0.41232:010 00100, 0.60208:01000100, 0.37136:01000100, 0.34608:01000100, 0.55056:01000100, 0 .42768:01000100, 0.56112:05000780, 0.52807:00000000, 4.33016:DC040000, 7.40748:0 10000000000010C00000000, 7.57132:000000000000000005000780, 1.63016:32000000, 4.3 9640:DC040000, 8.45434:EC5537826FAD8844ABBA433565F1D57205000780, 5.10786:0000000 031352E32302E313232382E3032303A564931505230314D42323939303A38616433323065392D646
    338612D343530642D386265322D62646464616261333932613900602005000780,
    255.1750:4B01 0000, 255.31418:0A004C82, 0.22753:50010000, 255.21817:DC040000, 4.60547:DC040000 , 0.21966:B4100000, 4.30158:DC040000 [Hostname=abc]')</p>
  </blockquote>
  
  <p>Only help I got on the internet was from the page - <a href="https://support.microsoft.com/en-us/help/3132755/554-5-2-0-storedrv-deliver-exception-objectnotfoundexception-mapiexcep" rel="nofollow noreferrer">https://support.microsoft.com/en-us/help/3132755/554-5-2-0-storedrv-deliver-exception-objectnotfoundexception-mapiexcep</a>
  And it seems to say clutter is enabled but the folder is not present in the mailbox and suggests to turn off the clutter option which didn’t help.</p>
  
  <p>PS - This works from my local machine within my company network but it is something to do with running it from Azure server.</p>