Hi Guys,
The idea is that I must only iterate for every mail in Outlook 2007
inbox folder, and those mail which passed my conditions, I must moved to
subfoler named "Archive". This is only a few lines of code, but even
with this a have problem:(, and the worst thing is that I need this to
my work for tommorrow. My code work fine.....but only for 1 mail...and I
dont't know why? For example I sent to my e-mail account set up in
Outlook 3 mails which are consistend with my conditions (for example
every 3 mails have no subject and they have only 1 attachment), and run
my application in VS 2008, then I look in Outlook and I see that only
one of those three mails have been moved, If I run app, next mail will
be moved to Archive subfolder, and like that....I don't know why he
don't do this at once as I iterate using foreach? It's not logical for
me:(
This is my very small code:
Microsoft.Office.Interop.Outlook.Application outlook = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.NameSpace names = outlook.GetNamespace("MAPI");
Microsoft.Office.Interop.Outlook.MAPIFolder odbiorcza = names.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
Microsoft.Office.Interop.Outlook.MAPIFolder archive =
names.GetDefaultFolder(OlDefaultFolders.olFolderInbox).Folders["Archive"];
if (odbiorcza.Items.Count > 0)
{
foreach (Microsoft.Office.Interop.Outlook.MailItem mail in odbiorcza.Items)
{
if (mail.Subject == null || mail.Subject.StartsWith("WWY"))
{
MessageBox.Show(mail.SenderName.ToString());
if (mail.Attachments.Count == 1)
{
mail.Move(archive);
}
}
}
}
I would be very gratefully for every advice and tip, really!
And sorry for my language, but I'm just learning english
Best Greets
Michael
Loading
PiotrPosted May 2, 2012, 7:48 AM
If you are sure there is no your code waiting for input you may just call for keypressed event, or try close console.
Regards
Piotr
michal adamkiewiczmPosted Apr 25, 2012, 5:51 PM
VulpesPosted Apr 25, 2012, 5:13 PM
You could have got around this by using a 'for' rather than a 'foreach' loop and iterating backwards through the collection but, if the code's working now, I wouldn't alter it.
Which method are you calling when the warning message pops up - is it the Move method?
michal adamkiewiczmPosted Apr 25, 2012, 4:53 PM
Only one little thing now is, that I cant resolve a problem with the warning message generated from Outlook that, some program want to acces to your personal informations etc....If I click allow everythink is oki, but the those few lines of code which You helped me, will be runned from macro in Access VBA, so It must be automaticly in 100%, that why this warning message crossed a bit my plans:(
VulpesPosted Apr 25, 2012, 4:32 PM
michal adamkiewiczmPosted Apr 25, 2012, 4:18 PM
VulpesPosted Apr 25, 2012, 4:07 PM