1

I created a program for when the user runs it, it emails an attachment to him/her self. The code right is when a different user runs it, the code needs to be change to the different user (which is not efficient). Is there a python code to identify the person running the program's outlook email address and sends it to him/her self. I am using win32com.

instead of

mail.to "email address"

to

mail.to "user of the program"
Johnseito
  • 315
  • 1
  • 9
  • 24
  • To answer your second question I would check out [this question on using the os module](https://stackoverflow.com/questions/842059/is-there-a-portable-way-to-get-the-current-username-in-python) and if all you need is the username it should work. If there are other factors which might change the email address in outlook or require a bit more exactness it would take calling the ADSI and I would take a look at [this](https://stackoverflow.com/questions/18146970/how-to-get-process-owner-by-python-using-wmi). If you really need the email address assigned by ADSI to MAPI- use PS and pipe the output – LinkBerest Jul 22 '17 at 16:47
  • Basically, ADSI (Active Directory Service Interfaces) is just a portion of the COM interfaces which includes the username. MAPI (Messaging Application Programming Interface) is an API connected to outlook. PS is Powershell (basically the Windows scripting language). A lot of work I do with MS systems I start with a PS wrapper which just grabs a bunch of information and passes that to the Python program which then does the work (usually after putting the info in a dict, named tuple, or passing it to a class). – LinkBerest Jul 22 '17 at 17:51
  • Thanks for the abundance of information but what is ADSI and MAPI, and use PS and pipe the output mean and how is that method or process use ? How long is that process. I guess if there are a lot of emails in the system than it takes very long to process ? The email is unpredictable in the sense that for some people it could be firstname.lastname@abc.com or others lastname.firstname@xyz.com or firstname.middleinitial.lastname@123.com etc – Johnseito Jul 22 '17 at 17:55

1 Answers1

-1

Using Outlook Object Model, read the Application.Session.CurrentUser.Address property. In case of Exchange, SMTP address can be retrieved from Application.Session.CurrentUser.AddressEntry.GetExchangeUser().PrimarySmtpAddress (be prepared to handle nulls and exceptions).

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78