Fun with Outlook and MAPI

C

Chris

I'm trying to send an e-mail through outlook. So far I've gotten it to
work with the mail script at
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/149461 My only
problem is that when I call Resolve() and Send(), I get confirmation
dialogs. I will be sending out quite a few e-mails at a time, and would
rather not have the user have to click yes for every single one. Does
anyone know a workaround? I know about smtplib, but I would prefer to
simply make what I have work. Thanks.

Chris
 
W

Will McGugan

Chris said:
I'm trying to send an e-mail through outlook. So far I've gotten it to
work with the mail script at
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/149461 My only
problem is that when I call Resolve() and Send(), I get confirmation
dialogs. I will be sending out quite a few e-mails at a time, and would
rather not have the user have to click yes for every single one. Does
anyone know a workaround? I know about smtplib, but I would prefer to
simply make what I have work. Thanks.

Alas, I dont think that there is much you can do to prevent the
confirmation dialogs with Outlook's MAPI dll. MS added them in a service
pack as an anti-virus measure, so no work-around. Not all clients show
these anoying dialogs though. Thunderbird definately doesn't.


Regards,

Will McGugan
 
D

David Fraser

Will said:
Alas, I dont think that there is much you can do to prevent the
confirmation dialogs with Outlook's MAPI dll. MS added them in a service
pack as an anti-virus measure, so no work-around. Not all clients show
these anoying dialogs though. Thunderbird definately doesn't.

There is actually a workaround. You're using Simple MAPI which has a
nice easy interface. The confirmation dialogs are only for Simple MAPI.
Using Extended MAPI can work around the problem but its a lot more tricky.
See the initial discussion here:
http://aspn.activestate.com/ASPN/Mail/Message/Python-win32/2160646

This code has now been included in pywin32 somehow but I can't remember
where and its late. Should also be a cookbook entry. Maybe Google can
help :)

David
 
C

Chris

Will said:
Alas, I dont think that there is much you can do to prevent the
confirmation dialogs with Outlook's MAPI dll. MS added them in a service
pack as an anti-virus measure, so no work-around. Not all clients show
these anoying dialogs though. Thunderbird definately doesn't.

Unfortunately, I don't have the option of installing Thunderbird.

Chris
 
C

Chris

Alas, I dont think that there is much you can do to prevent the
There is actually a workaround. You're using Simple MAPI which has a
nice easy interface. The confirmation dialogs are only for Simple MAPI.
Using Extended MAPI can work around the problem but its a lot more tricky.
See the initial discussion here:
http://aspn.activestate.com/ASPN/Mail/Message/Python-win32/2160646

This code has now been included in pywin32 somehow but I can't remember
where and its late. Should also be a cookbook entry. Maybe Google can
help :)

Cool. I'll take a look an' see if I can get it to work. MAPI has
turned out to be a major PITA. Especially when trying to learn it and
Python at the same time. :)

Chris
 
L

Larry Bates

At the risk of beating a dead horse, but you really should consider
using SMTP instead if you are really going to be sending a lot
of messages. I think you will find it more reliable and much faster.
It also eliminates the need for ANY email client to be on the machine
that is sending the messages.

http://motion.technolust.cx/related/send_jpg.py

Here is a link to a class that wraps everything up very nicely. You
should be able to be sending SMTP emails with it in 10-15 minutes.
It supports binary attachments as well.

FYI,
Larry Bates
 
R

Roger Binns

Chris said:
My only problem is that when I call Resolve() and Send(), I get confirmation dialogs. I will be sending out quite a few e-mails
at a time, and would rather not have the user have to click yes for every single one.

Here is an simple workaround:

http://www.contextmagic.com/express-clickyes/

If you have win32all installed, you can even use the programming API
they present to turn on and off the clickyes functionality.

Roger
 
R

Roger Binns

Larry Bates said:
At the risk of beating a dead horse, but you really should consider
using SMTP instead if you are really going to be sending a lot
of messages.

The problem is that doesn't work in more complicated configurations
such as when authentication and/or SSL have to happen, not to mention
the issue of configuring servers and ports, that users have already
configured in their mail clients. Additionally when you use MAPI,
messages that you send also end up in your sent items folder. (I
also have not had any issue sending lots of messages using MAPI).

Ultimately the utility of vanilla of pure SMTP will depend on
customer requirements and how simple the configuration is.

Roger
 
S

Steve Holden

Chris said:
Cool. I'll take a look an' see if I can get it to work. MAPI has
turned out to be a major PITA. Especially when trying to learn it and
Python at the same time. :)

Chris

There's recently been some discussion of this topic on the python-win32
list, most lately to accommodate moving sent messages to the Sent
folder. I've personally sent several hundred messages using the
techniques outlined there.

http://mail.python.org/pipermail/python-win32/2004-August/002239.html is
a good starting point.

regards
Steve
 
C

Chris

At the risk of beating a dead horse, but you really should consider
The problem is that doesn't work in more complicated configurations
such as when authentication and/or SSL have to happen, not to mention
the issue of configuring servers and ports, that users have already
configured in their mail clients. Additionally when you use MAPI,
messages that you send also end up in your sent items folder. (I
also have not had any issue sending lots of messages using MAPI).

Ultimately the utility of vanilla of pure SMTP will depend on
customer requirements and how simple the configuration is.

That pretty much sums it up. Also, since everything is done over IMAP
with Outlook, I don't really have access to an SMTP server.

Chris
 
C

Chris

There is actually a workaround. You're using Simple MAPI which has a
nice easy interface. The confirmation dialogs are only for Simple MAPI.
Using Extended MAPI can work around the problem but its a lot more tricky.
See the initial discussion here:
http://aspn.activestate.com/ASPN/Mail/Message/Python-win32/2160646

This code has now been included in pywin32 somehow but I can't remember
where and its late. Should also be a cookbook entry. Maybe Google can
help :)

Okay, here's the results. The good news is that the code sent the mail
without any popup's. The bad news is that the sent e-mail stays in the
outbox instead of the sent folder. Any suggestions?

Chris
 
S

Steve Holden

Chris said:
Okay, here's the results. The good news is that the code sent the mail
without any popup's. The bad news is that the sent e-mail stays in the
outbox instead of the sent folder. Any suggestions?

Chris

Well, only the same one I've already made, which is to look on the
win32all mailing list archives. Since this appears to be beyond you,
here's a note by Chad Stryker commenting on an original work by David
Fraser.

It may give you the clues you need, otherwise Google for the whole
thread(s).

"""Thank you for figuring this extended MAPI interface all out. I
discovered a couple of problems with the code (on my system at least).
First, the message in my outbox was marked as read. Second, the message
would remain in the outbox after it was sent. After several hours of
work, I added three lines to the function that mark the message as
unread and cause the message to be deleted from the outbox after it is sent.

First, I added a constant that I found in the MAPI header file MAPIDefS.h.

CLEAR_READ_FLAG = 4

Next I added two lines just before “outboxfolder.SaveChanges(0)”.

message.SetReadFlag(CLEAR_READ_FLAG)
message.SetProps([(mapitags.PR_DELETE_AFTER_SUBMIT,1)])

With these changes, the behavior in the outbox is consistent with
sending messages directly from Outlook.
"""

regards
Steve
 
C

Chris

Okay, here's the results. The good news is that the code sent the
mail without any popup's. The bad news is that the sent e-mail stays
in the outbox instead of the sent folder. Any suggestions?
Well, only the same one I've already made, which is to look on the
win32all mailing list archives. Since this appears to be beyond you,
here's a note by Chad Stryker commenting on an original work by David
Fraser.

It may give you the clues you need, otherwise Google for the whole
thread(s).

"""Thank you for figuring this extended MAPI interface all out. I
discovered a couple of problems with the code (on my system at least).
First, the message in my outbox was marked as read. Second, the message
would remain in the outbox after it was sent. After several hours of
work, I added three lines to the function that mark the message as
unread and cause the message to be deleted from the outbox after it is
sent.

First, I added a constant that I found in the MAPI header file MAPIDefS.h.

CLEAR_READ_FLAG = 4

Next I added two lines just before “outboxfolder.SaveChanges(0)”.

message.SetReadFlag(CLEAR_READ_FLAG)
message.SetProps([(mapitags.PR_DELETE_AFTER_SUBMIT,1)])

With these changes, the behavior in the outbox is consistent with
sending messages directly from Outlook.
"""

regards
Steve

Actually, I had already found that message. It still doesn't do what
I'm looking for(namely moving sent messages to the Sent folder).

Chris
 
S

Steve Holden

Chris said:
Okay, here's the results. The good news is that the code sent the
mail without any popup's. The bad news is that the sent e-mail stays
in the outbox instead of the sent folder. Any suggestions?

Well, only the same one I've already made, which is to look on the
win32all mailing list archives. Since this appears to be beyond you,
here's a note by Chad Stryker commenting on an original work by David
Fraser.

It may give you the clues you need, otherwise Google for the whole
thread(s).

"""Thank you for figuring this extended MAPI interface all out. I
discovered a couple of problems with the code (on my system at least).
First, the message in my outbox was marked as read. Second, the
message would remain in the outbox after it was sent. After several
hours of work, I added three lines to the function that mark the
message as unread and cause the message to be deleted from the outbox
after it is sent.

First, I added a constant that I found in the MAPI header file
MAPIDefS.h.

CLEAR_READ_FLAG = 4

Next I added two lines just before “outboxfolder.SaveChanges(0)”.

message.SetReadFlag(CLEAR_READ_FLAG)
message.SetProps([(mapitags.PR_DELETE_AFTER_SUBMIT,1)])

With these changes, the behavior in the outbox is consistent with
sending messages directly from Outlook.
"""

regards
Steve


Actually, I had already found that message. It still doesn't do what
I'm looking for(namely moving sent messages to the Sent folder).

Chris
Well, in that case please excuse my crotchetiness. It's probably the
time of year.

bah-humbug-ly y'rs - steve
 

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,185
Members
46,738
Latest member
JinaMacvit

Latest Threads

Top