title: How to get current users email address for Python error reporting?
body: <p>We're currently using a super basic Python script that I found online a while ago to send an error report via HTML from out departmental email address. However, as it currently stands, it sends the email <em>from</em> our email address <em>to</em> our email address. I'm hoping there might be some way to send the email from the address of the current user. Here's what we've got:</p>
  
  <pre><code>def sendMail(sender, recipient, subject, html, text):
  
  import MimeWriter, mimetools, cStringIO
  import smtplib
  out = cStringIO.StringIO()
  htmlin = cStringIO.StringIO(html)
  txtin = cStringIO.StringIO(text)
  
  writer = MimeWriter.MimeWriter(out)
  writer.addheader("From", sender)
  writer.addheader("To", recipient)
  writer.addheader("Subject", subject)
  writer.addheader("MIME-Version", "1.0")
  writer.startmultipartbody("alternative")
  writer.flushheaders()
  
  subpart = writer.nextpart()
  subpart.addheader("Content-Transfer-Encoding", "quoted-printable")
  pout = subpart.startbody("text/plain", [("charset", 'us-ascii')])
  mimetools.encode(txtin, pout, 'quoted-printable')
  txtin.close()
  
  subpart = writer.nextpart()
  subpart.addheader("Content-Transfer-Encoding", "quoted-printable")
  
  pout = subpart.startbody("text/html", [("charset", 'us-ascii')])
  mimetools.encode(htmlin, pout, 'quoted-printable')
  htmlin.close()
  writer.lastpart()
  msg = out.getvalue()
  server = smtplib.SMTP('smtp.office365.com',587)
  server.ehlo()
  server.starttls()
  server.ehlo()
  server.login("sample@email.com","sample")
  server.sendmail(sender, recipient, msg)
  server.quit()
  </code></pre>
  
  <p>Then we're using a simple try/except execfile script to run everything from:</p>
  
  <pre><code>try:
  execfile('\\\\path.py')
  except:
  print 'ATTENTION: An error has been detected in a script process.'
  traceback.print_exc(file=sys.stdout)
  
  import sys, cgitb
  recipient =   
  ['sample@email.com','sample2@email.com','sample3@email.com','sample4@email.com']
  for rec in recipient:
      Utils.sendMail('sample@email.com',
          rec,
          'ATTENTION: An error has been detected in a script process...',
          cgitb.html(sys.exc_info()),
          cgitb.text(sys.exc_info()))
  sys.exit()
  </code></pre>
  
  <p>It's here where we define the address we're sending to:</p>
  
  <pre><code> for rec in recipient:
      Utils.sendMail('sample@email.com',
          rec,
          'ATTENTION: An error has been detected in a script process...',
          cgitb.html(sys.exc_info()),
          cgitb.text(sys.exc_info()))
  sys.exit()
  </code></pre>
  
  <p>Is there some kind of AD script we can implement here? We've got about 30 people using our processes so whenever an error pops up all we get is an email with the error and no reference to who it belongs to. </p>