Congratulations on solving it yourself! I'm glad to see you continued to work through your problem after posting it here. | [reply] |
I noticed you worked on Outlook & OLE (quite a long time ago) - I'm currently working on that too and I'd like to get your insights on the whole thing : I want to find out whether there's an active email open and how to retrieve the text from that email. Note that since it's a new mail, it is highly unlikely that it's been saved.
I did the same with Word and Excel easily enough (even though I must admit I did have a bit a trouble there as well) but it seems to me Outlook is not as easy.
Please let me know if you come across anything that could be helpful.
Thanks, David.
Heureux qui, comme Ulysse, a fait un beau voyage
Ou comme celui-là qui conquit la Toison,
Et puis est retourné plein d'usage et raison,
Vivre entre ses parents le reste de son âge!
J. du Bellay, poëte angevin
| [reply] |
Any time you have an Outlook item open in a separate window, it's in an Inspector.
What I would do in this case is get the list of all the Inspectors, filter out the ones that aren't open on a Mail item, and then, if necessary, apply further filtering on the contents of the item. For example:
use Win32::OLE;
use Win32::OLE::Const '.*Outlook'; # load the relevant constants
my $ol = new Win32::OLE 'Outlook.Application';
my $inspectors = $ol->Inspectors;
my @inspectors = Win32::OLE::Enum->new( $inspectors )->All;
my @mail_items =
grep { $_->Class == olMail }
map { $_->CurrentItem } # get the MailItem object
@inspectors;
You could, perhaps, try to rely on the fact that for a brand spanking new mail message, the Inspector has a caption (that is, its window has a title)
of Untitled - Message (Plain Text)
my @mail_items =
grep { $_->Class == olMail }
map { $_->CurrentItem } # get the MailItem object
grep { $_->Caption eq 'Untitled - Message (Plain Text)' }
@inspectors;
Once you've found the element in @mail_items which is the one you want, you can extract its body text with the Body method, of course.
jdporter The 6th Rule of Perl Club is -- There is no Rule #6. | [reply] [d/l] [select] |