Python MAPI

K

kyosohma

Hi,

I've been googling all over and can't find any good answers about this
problem. I would like to create some kind of MAPI interface with
Python such that when I open Microsoft Word (or another Office
program) and click File, Send To, Mail Recipient it opens a program I
wrote in Python and uses it to send the email rather than Outlook.

The closest I've come is finding the registry key HKLM\Software\Clients
\Mail which seems to control the default email client. I did figure
out how to redirect mailto directives on websites to my program
successfully, but this is a whole 'nother ballgame.

Any suggestions are welcome. I am considering writing some VBA hooks
in Office Apps in question, but would prefer to avoid that.

Thanks!

Mike

P.S. Currently using Python 2.4, wxPython 2.8.3 (for GUI) on Windows
XP Pro.
 
V

vasudevram

Hi,

I've been googling all over and can't find any good answers about this
problem. I would like to create some kind of MAPI interface with
Python such that when I open Microsoft Word (or another Office
program) and click File, Send To, Mail Recipient it opens a program I
wrote in Python and uses it to send the email rather than Outlook.

The closest I've come is finding the registry key HKLM\Software\Clients
\Mail which seems to control the default email client. I did figure
out how to redirect mailto directives on websites to my program
successfully, but this is a whole 'nother ballgame.

Any suggestions are welcome. I am considering writing some VBA hooks
in Office Apps in question, but would prefer to avoid that.

Thanks!

Mike

P.S. Currently using Python 2.4, wxPython 2.8.3 (for GUI) on Windows
XP Pro.

Hi,

1: I don't know much about Windows APIs, but am currently reading the
"Windows Internals" book. Got this idea from it:

Go to http://www.microsoft.com/technet/sysinternals/default.mspx
and check out the SysInternals utilities there. The book says that you
can use some of them to "spy" on what an app is doing - what registry
keys it is reading/writing, lots of other OS-level calls it makes as
it runs. Digging around and using some of these utilities to check out
what an Office app does when you use it to send mail, might help you
figure out a way to do what you want.

2. Try looking for registry entries specific to Office Apps, and look
under those subtrees for likely email-related entries to modify (if
you haven't tried that already). I guess you already know that
fiddling with the registry can be risky and can crash your system, so
take backups, etc.

Using COM via Python may also help - again, some digging required. You
probably already have the PyWin32 Python extensions for Windows COM
(earlier called win32all - see http://wiki.python.org/moin/Win32All) -
if not, its available here:

http://www.python.org/download/releases/2.4.4/
(scroll down the page for the link)

Vasudev Ram
www.dancingbison.com
jugad.livejournal.com
sourceforge.net/projects/xtopdf
 
K

kyosohma

Hi,

1: I don't know much about Windows APIs, but am currently reading the
"Windows Internals" book. Got this idea from it:

Go tohttp://www.microsoft.com/technet/sysinternals/default.mspx
and check out the SysInternals utilities there. The book says that you
can use some of them to "spy" on what an app is doing - what registry
keys it is reading/writing, lots of other OS-level calls it makes as
it runs. Digging around and using some of these utilities to check out
what an Office app does when you use it to send mail, might help you
figure out a way to do what you want.

2. Try looking for registry entries specific to Office Apps, and look
under those subtrees for likely email-related entries to modify (if
you haven't tried that already). I guess you already know that
fiddling with the registry can be risky and can crash your system, so
take backups, etc.

Using COM via Python may also help - again, some digging required. You
probably already have the PyWin32 Python extensions for Windows COM
(earlier called win32all - seehttp://wiki.python.org/moin/Win32All) -
if not, its available here:

http://www.python.org/download/releases/2.4.4/
(scroll down the page for the link)

Vasudev Ramwww.dancingbison.com
jugad.livejournal.com
sourceforge.net/projects/xtopdf

Thanks for the ideas...I am already monitoring the registry to see
what happens when I switch between two email clients. In this case, I
am switching between Outlook 2003 and Thunderbird 2. The pertinent
registry files are as follows:

# changes which email client to use
[HKEY_LOCAL_MACHINE\SOFTWARE\Clients\Mail]

# obviously changes the .eml file association
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.eml]

# haven't the fogiest idea what this does, if anything
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{29F458BE-8866-11D5-
A3DD-00B0D0F3BAA7}]

# change mailto functionality
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\mailto\DefaultIcon]
@="C:\\Program Files\\Mozilla Thunderbird\\thunderbird.exe,0"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\mailto\shell\open\command]
@="\"C:\\Program Files\\Mozilla Thunderbird\\thunderbird.exe\" -osint -
compose \"%1\""

I assume you're referring to "Process Monitor", which is a really cool
tool. Maybe it'll help, but I usually can't get it to filter out
enough of the noise to make the output useful. I'll give it a go
nonethless.

I am running all my tests in a VM, so I really don't care if the
registry gets hosed at this point.

Thanks again,

Mike
 
V

vasudevram

On Jul 20, 10:57 pm, (e-mail address removed) wrote:

1: I don't know much about Windows APIs, but am currently reading the
"Windows Internals" book. Got this idea from it:
Go tohttp://www.microsoft.com/technet/sysinternals/default.mspx
and check out the SysInternals utilities there. The book says that you
can use some of them to "spy" on what an app is doing - what registry
keys it is reading/writing, lots of other OS-level calls it makes as
it runs. Digging around and using some of these utilities to check out
what an Office app does when you use it to send mail, might help you
figure out a way to do what you want.
2. Try looking for registry entries specific to Office Apps, and look
under those subtrees for likely email-related entries to modify (if
you haven't tried that already). I guess you already know that
fiddling with the registry can be risky and can crash your system, so
take backups, etc.
Using COM via Python may also help - again, some digging required. You
probably already have the PyWin32 Python extensions for Windows COM
(earlier called win32all - seehttp://wiki.python.org/moin/Win32All) -
if not, its available here:
Vasudev Ramwww.dancingbison.com
jugad.livejournal.com
sourceforge.net/projects/xtopdf

Thanks for the ideas...I am already monitoring the registry to see
what happens when I switch between two email clients. In this case, I
am switching between Outlook 2003 and Thunderbird 2. The pertinent
registry files are as follows:

# changes which email client to use
[HKEY_LOCAL_MACHINE\SOFTWARE\Clients\Mail]

# obviously changes the .eml file association
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.eml]

# haven't the fogiest idea what this does, if anything
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{29F458BE-8866-11D5-
A3DD-00B0D0F3BAA7}]

# change mailto functionality
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\mailto\DefaultIcon]
@="C:\\Program Files\\Mozilla Thunderbird\\thunderbird.exe,0"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\mailto\shell\open\command]
@="\"C:\\Program Files\\Mozilla Thunderbird\\thunderbird.exe\" -osint -
compose \"%1\""

I assume you're referring to "Process Monitor", which is a really cool
tool. Maybe it'll help, but I usually can't get it to filter out
enough of the noise to make the output useful. I'll give it a go
nonethless.

I am running all my tests in a VM, so I really don't care if the
registry gets hosed at this point.

Thanks again,

Mike- Hide quoted text -

- Show quoted text -

You're welcome :)

If Process Monitor has an option to save its output as text files /
CSV files (some of the other SysInternals tools do), you might want to
try using (a Windows version) of grep or awk to filter out the
noise ..

Vasudev
 
K

kyosohma

If Process Monitor has an option to save its output as text files /
CSV files (some of the other SysInternals tools do), you might want to
try using (a Windows version) of grep or awk to filter out the
noise ..

Vasudev

Well, I ran Process Monitor with some filters enabled to only watch
Thunderbird and MS Word. Unfortunately, that didn't give me any of the
registry edits, so I disabled my filters and ran it without. Now I
have a log file with 28,000 entries. It's amazing to see all the stuff
that happens in just a few moments, but how am I supposed to parse
this mess?

Explorer.exe and outlook express do thousands of the registry calls
and the paths they manipulate vary wildly. Oh well, I'll be off the
clock in about 15 minutes so it can wait until Monday.

Thanks for your help. I'll post if I figure out anything...hopefully
you'll do the same.

Mike
 
M

memracom

Well, I ran Process Monitor with some filters enabled to only watch
Thunderbird and MS Word. Unfortunately, that didn't give me any of the
registry edits, so I disabled my filters and ran it without. Now I
have a log file with 28,000 entries. It's amazing to see all the stuff
that happens in just a few moments, but how am I supposed to parse
this mess?

I expect you will find it easier figuring out how to install your app
in the SendTo menu rather than making your app callable via MAPI. This
probably involves ShellExtensions but I believe there are utilities
that can be used to add any arbitrary application to the SendTo menu.
That may be enough for your application.

You might want to have a look at SpamBayes for an example of an
Outlook extension written in Python to get an idea of how you can
interface with Outlook.
 
K

kyosohma

I expect you will find it easier figuring out how to install your app
in the SendTo menu rather than making your app callable via MAPI. This
probably involves ShellExtensions but I believe there are utilities
that can be used to add any arbitrary application to the SendTo menu.
That may be enough for your application.

You might want to have a look at SpamBayes for an example of an
Outlook extension written in Python to get an idea of how you can
interface with Outlook.

We may add it to the Sendto menu, but we have users that want to be
able to use the email functionality from within Office Apps. I've been
planning on reading the SpamBayes source code anyway...however, we're
trying to move away from Outlook. We're currently using Zimbra now and
that's why I'd like to open my Python program with MAPI so I can send
email through our new Zimbra mail server.

I have interfaced with Outlook before using COM, but it's not pretty.

Mike
 
V

vasudevram

Well, I ran Process Monitor with some filters enabled to only watch
Thunderbird and MS Word. Unfortunately, that didn't give me any of the
registry edits, so I disabled my filters and ran it without. Now I
have a log file with 28,000 entries. It's amazing to see all the stuff
that happens in just a few moments, but how am I supposed to parse
this mess?

Explorer.exe and outlook express do thousands of the registry calls
and the paths they manipulate vary wildly. Oh well, I'll be off the
clock in about 15 minutes so it can wait until Monday.

Thanks for your help. I'll post if I figure out anything...hopefully
you'll do the same.

---

Sorry for not replying earlier ... I searched this list for the topic
(Python MAPI) a few times but couldn't find it - not sure why - maybe
Google Groups's indexing gets messed up sometimes ...

Yes, so many entries would be a problem to parse manually ...

That's why I suggested using a grep for Windows - or, preferably, an
egrep - which is a more powerful version of grep; e.g. basic grep only
allows you to use one regexp at a time - while egrep allows you to use
extended regular expressions, such as "pattern1|pattern2", also
"patt(e|u)rn(1|2)" which looks in parallel for pattern1, patturn1,
pattern2 and patturn2 - I used a made-up example where the spelling of
pattern could be wrong, but it works for any other cases of
alternative patterns and subpatterns as well. Not sure if there is any
egrep for Windows - try Googling. If not, and the problem is important
enough, you might want to install Cygwin (its a big download, so first
check if it _does_ have egrep in it).

Vasudev
 
K

kyosohma

Thunderbird and MS Word. Unfortunately, that didn't give me any of the
registry edits, so I disabled my filters and ran it without. Now I
have a log file with 28,000 entries. It's amazing to see all the stuff
that happens in just a few moments, but how am I supposed to parse
this mess?

Explorer.exe and outlook express do thousands of the registry calls
and the paths they manipulate vary wildly. Oh well, I'll be off the
clock in about 15 minutes so it can wait until Monday.

Thanks for your help. I'll post if I figure out anything...hopefully
you'll do the same.

---

Sorry for not replying earlier ... I searched this list for the topic
(Python MAPI) a few times but couldn't find it - not sure why - maybe
Google Groups's indexing gets messed up sometimes ...

Yes, so many entries would be a problem to parse manually ...

That's why I suggested using a grep for Windows - or, preferably, an
egrep - which is a more powerful version of grep; e.g. basic grep only
allows you to use one regexp at a time - while egrep allows you to use
extended regular expressions, such as "pattern1|pattern2", also
"patt(e|u)rn(1|2)" which looks in parallel for pattern1, patturn1,
pattern2 and patturn2 - I used a made-up example where the spelling of
pattern could be wrong, but it works for any other cases of
alternative patterns and subpatterns as well. Not sure if there is any
egrep for Windows - try Googling. If not, and the problem is important
enough, you might want to install Cygwin (its a big download, so first
check if it _does_ have egrep in it).

Vasudev

There are some programs that do grep for Windows. I'll mess with them.

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top