SirReadAlot
asked on
outlook programming in c#
Hi experts,
just wondering if anyone knows how to program outlook via c#.
I have built a console application which arranges my outlook messages into folders. for exmple if the its an
unopened email msg, the console app leaves that particular msg, else every read msg gets moved to my junk folder.
What I want to do now is be able to find every replied email with no attachments to the bin folder.
How do i accomplish this. Any relavant articles or code will be nice
thanks
pls add reference to Microsoft.Office.Interop.O utlook; thanks
This is what i have done so far. it works well. see code below
========================== ========== ========== ==
using System;
using Microsoft.Office.Interop.O utlook;
namespace EmailSorter
{
/// <summary>
/// Summary description for Loader.
/// </summary>
public class Loader
{
private static Application oApp;
private static NameSpace oNS;
private static Recipient oUser;
private static MAPIFolder oFolder;
private static MAPIFolder oReadNotActionedDestinatio nFolder;
private static MAPIFolder oReadDestinationFolder;
private static MAPIFolder oSentFolder;
private static MAPIFolder oDeletedFolder;
[STAThread]
static void Main(string[] args)
{
Console.WriteLine("outlook inbox manager");
Console.WriteLine(" In progress");
Console.WriteLine(" Loading outlook folders");
inistialiseFolders();
//MailItem oMsg = (MailItem)oItems.GetFirst( );
int iCount = 0;
int iNewCount = 1;
Console.WriteLine(" Processing mail items");
while (iCount != iNewCount)
{
Items oItems = oFolder.Items;
iCount = oItems.Count;
for (int i=1; i<=iCount; i++)
{
try
{
MailItem oMsg = (MailItem)oItems[i];
Console.WriteLine(" Mail item: " + oMsg.Subject);
if (!oMsg.UnRead && hasBeenActioned(oMsg.Subje ct))
{
oMsg.Move(oReadDestination Folder);
Console.WriteLine(" moved to junk folder");
}
if (!oMsg.Sent && hasBeenSent())
{
oMsg.Move(oDeletedFolder);
Console.WriteLine(" Deleted");
}
if (!oMsg.UnRead)
{
oMsg.Move(oReadNotActioned Destinatio nFolder);
Console.WriteLine(" task created");
}
else
{
Console.WriteLine(" not touched");
}
}
catch (System.InvalidCastExcepti on ice)
{
Console.WriteLine(" Not an item of mail");
}
catch {}
}
iNewCount = oItems.Count;
}
Console.WriteLine("Complet ed");
Console.WriteLine("Press enter to exit application");
Console.Read();
}
private static bool hasBeenActioned (string mailSubject)
{
bool retval = false;
for (int i=1; i<=oSentFolder.Items.Count && retval==false; i++)
{
try
{
MailItem msg = (MailItem)oSentFolder.Item s[i];
if (msg.Subject == mailSubject)
{
retval = true;
}
}
catch{}
}
return retval;
}
private static bool hasBeenSent()
{
bool retval = false;
for (int i=1; i<=oDeletedFolder.Items.Co unt && retval==false; i++)
{
try
{
MailItem msg = (MailItem)oDeletedFolder.I tems[i];
if (msg.Sent)
{
retval = true;
}
}
catch{}
}
return retval;
}
private static void inistialiseFolders()
{
oApp = new ApplicationClass();
oNS = oApp.GetNamespace("MAPI");
oUser = oNS.CreateRecipient("Azunm a, Chi");
oFolder = oNS.GetSharedDefaultFolder (oUser, OlDefaultFolders.olFolderI nbox);
oReadNotActionedDestinatio nFolder = oNS.GetSharedDefaultFolder (oUser, OlDefaultFolders.olFolderT asks);
oReadDestinationFolder = oNS.GetSharedDefaultFolder (oUser, OlDefaultFolders.olFolderJ unk);
oSentFolder = oNS.GetDefaultFolder(OlDef aultFolder s.olFolder SentMail);
oDeletedFolder = oNS.GetDefaultFolder(OlDef aultFolder s.olFolder DeletedIte ms);
}
}
}
========================== ========== ========== ====
pl
just wondering if anyone knows how to program outlook via c#.
I have built a console application which arranges my outlook messages into folders. for exmple if the its an
unopened email msg, the console app leaves that particular msg, else every read msg gets moved to my junk folder.
What I want to do now is be able to find every replied email with no attachments to the bin folder.
How do i accomplish this. Any relavant articles or code will be nice
thanks
pls add reference to Microsoft.Office.Interop.O
This is what i have done so far. it works well. see code below
==========================
using System;
using Microsoft.Office.Interop.O
namespace EmailSorter
{
/// <summary>
/// Summary description for Loader.
/// </summary>
public class Loader
{
private static Application oApp;
private static NameSpace oNS;
private static Recipient oUser;
private static MAPIFolder oFolder;
private static MAPIFolder oReadNotActionedDestinatio
private static MAPIFolder oReadDestinationFolder;
private static MAPIFolder oSentFolder;
private static MAPIFolder oDeletedFolder;
[STAThread]
static void Main(string[] args)
{
Console.WriteLine("outlook
Console.WriteLine(" In progress");
Console.WriteLine(" Loading outlook folders");
inistialiseFolders();
//MailItem oMsg = (MailItem)oItems.GetFirst(
int iCount = 0;
int iNewCount = 1;
Console.WriteLine(" Processing mail items");
while (iCount != iNewCount)
{
Items oItems = oFolder.Items;
iCount = oItems.Count;
for (int i=1; i<=iCount; i++)
{
try
{
MailItem oMsg = (MailItem)oItems[i];
Console.WriteLine(" Mail item: " + oMsg.Subject);
if (!oMsg.UnRead && hasBeenActioned(oMsg.Subje
{
oMsg.Move(oReadDestination
Console.WriteLine(" moved to junk folder");
}
if (!oMsg.Sent && hasBeenSent())
{
oMsg.Move(oDeletedFolder);
Console.WriteLine(" Deleted");
}
if (!oMsg.UnRead)
{
oMsg.Move(oReadNotActioned
Console.WriteLine(" task created");
}
else
{
Console.WriteLine(" not touched");
}
}
catch (System.InvalidCastExcepti
{
Console.WriteLine(" Not an item of mail");
}
catch {}
}
iNewCount = oItems.Count;
}
Console.WriteLine("Complet
Console.WriteLine("Press enter to exit application");
Console.Read();
}
private static bool hasBeenActioned (string mailSubject)
{
bool retval = false;
for (int i=1; i<=oSentFolder.Items.Count
{
try
{
MailItem msg = (MailItem)oSentFolder.Item
if (msg.Subject == mailSubject)
{
retval = true;
}
}
catch{}
}
return retval;
}
private static bool hasBeenSent()
{
bool retval = false;
for (int i=1; i<=oDeletedFolder.Items.Co
{
try
{
MailItem msg = (MailItem)oDeletedFolder.I
if (msg.Sent)
{
retval = true;
}
}
catch{}
}
return retval;
}
private static void inistialiseFolders()
{
oApp = new ApplicationClass();
oNS = oApp.GetNamespace("MAPI");
oUser = oNS.CreateRecipient("Azunm
oFolder = oNS.GetSharedDefaultFolder
oReadNotActionedDestinatio
oReadDestinationFolder = oNS.GetSharedDefaultFolder
oSentFolder = oNS.GetDefaultFolder(OlDef
oDeletedFolder = oNS.GetDefaultFolder(OlDef
}
}
}
==========================
pl
ASKER
thanks for comming on board
I have 2003
I have 2003
Boy, you just zeroed right in on that one question. *GRIN*
There was another one in there:
Now, you want to find email messages that don't have attachments (msg.Attachments.Count > 0)?
Bob
There was another one in there:
Now, you want to find email messages that don't have attachments (msg.Attachments.Count > 0)?
Bob
Slight modification:
private static bool hasBeenSent()
{
bool retval = false;
foreach (MailItem msg in oDeletedFolder.Items)
if (msg.Sent)
{
retval = true;
break;
}
return retval;
}
I forgot the 'break' statement.
Bob
private static bool hasBeenSent()
{
bool retval = false;
foreach (MailItem msg in oDeletedFolder.Items)
if (msg.Sent)
{
retval = true;
break;
}
return retval;
}
I forgot the 'break' statement.
Bob
ASKER
yep,
Now, you want to find email messages that don't have attachments (msg.Attachments.Count > 0)?
i guess thats the next step.
Now, you want to find email messages that don't have attachments (msg.Attachments.Count > 0)?
i guess thats the next step.
Try this:
private static ArrayList GetEmailsWithAttachments(M APIFolder folder)
{
ArrayList list = new ArrayList;
foreach (MailItem msg in folder.Items)
if (msg.Attachments.Count > 0)
list.Add(msg);
return list;
}
Bob
private static ArrayList GetEmailsWithAttachments(M
{
ArrayList list = new ArrayList;
foreach (MailItem msg in folder.Items)
if (msg.Attachments.Count > 0)
list.Add(msg);
return list;
}
Bob
ASKER
okay, will try
ASKER
thanks,
Got this error,
namespace name 'ArrayList' could not be found (are you missing a using directive or an assembly reference?)
private static ArrayList GetEmailsWithAttachments(M APIFolder folder)
{
ArrayList list = new ArrayList();
foreach (MailItem msg in folder.Items)
if (msg.Attachments.Count > 0)
list.Add(msg);
return list;
}
namespace name 'ArrayList' could not be found (are you missing a using directive or an assembly reference?)
Got this error,
namespace name 'ArrayList' could not be found (are you missing a using directive or an assembly reference?)
private static ArrayList GetEmailsWithAttachments(M
{
ArrayList list = new ArrayList();
foreach (MailItem msg in folder.Items)
if (msg.Attachments.Count > 0)
list.Add(msg);
return list;
}
namespace name 'ArrayList' could not be found (are you missing a using directive or an assembly reference?)
ASKER
sorry solve it with
using System.Collections;
using System.Collections;
ASKER
What I want to do now is be able to find every replied email with no attachments and move it to the bin folder.
did the code work for you
using System;
using Microsoft.Office.Interop.O utlook;
using System.Collections;
namespace EmailSorter
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Loader
{
/// <summary>
/// The main entry point for the application.
/// </summary>
private static Application oApp;
private static NameSpace oNS;
private static Recipient oUser;
private static MAPIFolder oFolder;
private static MAPIFolder oReadNotActionedDestinatio nFolder;
private static MAPIFolder oReadDestinationFolder;
private static MAPIFolder oSentFolder;
private static MAPIFolder oDeletedFolder;
[STAThread]
static void Main(string[] args)
{
Console.WriteLine("KPMG outlook inbox manager");
Console.WriteLine(" In progress");
Console.WriteLine(" Loading outlook folders");
inistialiseFolders();
//MailItem oMsg = (MailItem)oItems.GetFirst( );
int iCount = 0;
int iNewCount = 1;
Console.WriteLine(" Processing mail items");
while (iCount != iNewCount)
{
Items oItems = oFolder.Items;
iCount = oItems.Count;
for (int i=1; i<=iCount; i++)
{
try
{
MailItem oMsg = (MailItem)oItems[i];
Console.WriteLine(" Mail item: " + oMsg.Subject);
if (!oMsg.UnRead && hasBeenActioned(oMsg.Subje ct))
{
oMsg.Move(oReadDestination Folder);
Console.WriteLine(" moved to junk folder");
}
if (!oMsg.Sent && hasBeenSent())
{
oMsg.Move(oDeletedFolder);
Console.WriteLine(" Deleted");
}
if (!oMsg.UnRead)
{
oMsg.Move(oReadNotActioned Destinatio nFolder);
Console.WriteLine(" task created");
}
else
{
Console.WriteLine(" not touched");
}
}
catch (System.InvalidCastExcepti on ice)
{
Console.WriteLine(" Not an item of mail");
}
catch {}
}
iNewCount = oItems.Count;
}
Console.WriteLine("Complet ed");
Console.WriteLine("Press enter to exit application");
Console.Read();
}
private static bool hasBeenActioned (string mailSubject)
{
bool retval = false;
for (int i=1; i<=oSentFolder.Items.Count && retval==false; i++)
{
try
{
MailItem msg = (MailItem)oSentFolder.Item s[i];
if (msg.Subject == mailSubject)
{
retval = true;
}
}
catch{}
}
return retval;
}
private static bool hasBeenSent()
{
bool retval = false;
foreach (MailItem msg in oDeletedFolder.Items)
if (msg.Sent)
{
retval = true;
break;
}
return retval;
}
private static ArrayList GetEmailsWithAttachments(M APIFolder folder)
{
ArrayList list = new ArrayList();
foreach (MailItem msg in folder.Items)
if (msg.Attachments.Count > 0)
list.Add(msg);
return list;
}
private static void inistialiseFolders()
{
oApp = new ApplicationClass();
oNS = oApp.GetNamespace("MAPI");
// oUser = oNS.CreateRecipient("Escot t, Robert");
oUser = oNS.CreateRecipient("Azunm a, Chi");
oFolder = oNS.GetSharedDefaultFolder (oUser, OlDefaultFolders.olFolderI nbox);
oReadNotActionedDestinatio nFolder = oNS.GetSharedDefaultFolder (oUser, OlDefaultFolders.olFolderT asks);
oReadDestinationFolder = oNS.GetSharedDefaultFolder (oUser, OlDefaultFolders.olFolderJ unk);
oSentFolder = oNS.GetDefaultFolder(OlDef aultFolder s.olFolder SentMail);
oDeletedFolder = oNS.GetDefaultFolder(OlDef aultFolder s.olFolder DeletedIte ms);
}
}
}
did the code work for you
using System;
using Microsoft.Office.Interop.O
using System.Collections;
namespace EmailSorter
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Loader
{
/// <summary>
/// The main entry point for the application.
/// </summary>
private static Application oApp;
private static NameSpace oNS;
private static Recipient oUser;
private static MAPIFolder oFolder;
private static MAPIFolder oReadNotActionedDestinatio
private static MAPIFolder oReadDestinationFolder;
private static MAPIFolder oSentFolder;
private static MAPIFolder oDeletedFolder;
[STAThread]
static void Main(string[] args)
{
Console.WriteLine("KPMG outlook inbox manager");
Console.WriteLine(" In progress");
Console.WriteLine(" Loading outlook folders");
inistialiseFolders();
//MailItem oMsg = (MailItem)oItems.GetFirst(
int iCount = 0;
int iNewCount = 1;
Console.WriteLine(" Processing mail items");
while (iCount != iNewCount)
{
Items oItems = oFolder.Items;
iCount = oItems.Count;
for (int i=1; i<=iCount; i++)
{
try
{
MailItem oMsg = (MailItem)oItems[i];
Console.WriteLine(" Mail item: " + oMsg.Subject);
if (!oMsg.UnRead && hasBeenActioned(oMsg.Subje
{
oMsg.Move(oReadDestination
Console.WriteLine(" moved to junk folder");
}
if (!oMsg.Sent && hasBeenSent())
{
oMsg.Move(oDeletedFolder);
Console.WriteLine(" Deleted");
}
if (!oMsg.UnRead)
{
oMsg.Move(oReadNotActioned
Console.WriteLine(" task created");
}
else
{
Console.WriteLine(" not touched");
}
}
catch (System.InvalidCastExcepti
{
Console.WriteLine(" Not an item of mail");
}
catch {}
}
iNewCount = oItems.Count;
}
Console.WriteLine("Complet
Console.WriteLine("Press enter to exit application");
Console.Read();
}
private static bool hasBeenActioned (string mailSubject)
{
bool retval = false;
for (int i=1; i<=oSentFolder.Items.Count
{
try
{
MailItem msg = (MailItem)oSentFolder.Item
if (msg.Subject == mailSubject)
{
retval = true;
}
}
catch{}
}
return retval;
}
private static bool hasBeenSent()
{
bool retval = false;
foreach (MailItem msg in oDeletedFolder.Items)
if (msg.Sent)
{
retval = true;
break;
}
return retval;
}
private static ArrayList GetEmailsWithAttachments(M
{
ArrayList list = new ArrayList();
foreach (MailItem msg in folder.Items)
if (msg.Attachments.Count > 0)
list.Add(msg);
return list;
}
private static void inistialiseFolders()
{
oApp = new ApplicationClass();
oNS = oApp.GetNamespace("MAPI");
// oUser = oNS.CreateRecipient("Escot
oUser = oNS.CreateRecipient("Azunm
oFolder = oNS.GetSharedDefaultFolder
oReadNotActionedDestinatio
oReadDestinationFolder = oNS.GetSharedDefaultFolder
oSentFolder = oNS.GetDefaultFolder(OlDef
oDeletedFolder = oNS.GetDefaultFolder(OlDef
}
}
}
There is the MailItem.ReplyRecipients.C ount > 0 option, but I am not sure if that will work.
Bob
Bob
ASKER
will try that.
at this stage, i will try anything!!
at this stage, i will try anything!!
ASKER
but did the code work for you?
ASKER
MailItem.ReplyRecipients.C ount > 0
did not work, i will try something else
did not work, i will try something else
ASKER
I stuxk break pionts here
if (!oMsg.Sent && hasBeenSent())
{
oMsg.Move(oDeletedFolder);
Console.WriteLine(" Deleted");
}
and its not even touching the code
if (!oMsg.Sent && hasBeenSent())
{
oMsg.Move(oDeletedFolder);
Console.WriteLine(" Deleted");
}
and its not even touching the code
I am not quite sure what you are trying to accomplish here, but I have noticed that in the 'hasBeenSent' function, you are looping through the Deleted Items folder. Is that what you want?
Bob
Bob
ASKER
opps, sorry about this!!
i fink we used the wrong thing here
"oMsg.Sent"
if msg has been read and no attachments then move bin (Deleted items folder)
if (!oMsg.Sent && hasBeenSent())
{
oMsg.Move(oDeletedFolder);
Console.WriteLine(" Moved to Deleted Items");
}
i fink we used the wrong thing here
"oMsg.Sent"
if msg has been read and no attachments then move bin (Deleted items folder)
if (!oMsg.Sent && hasBeenSent())
{
oMsg.Move(oDeletedFolder);
Console.WriteLine(" Moved to Deleted Items");
}
ASKER
what I would like is to move every message which has been read and has no attachments to the (Deleted items folder)
It's this line in 'hasBeenSent':
foreach (MailItem msg in oDeletedFolder.Items)
That's the Deleted Items folder. Should that be the Inbox folder instead?
Bob
foreach (MailItem msg in oDeletedFolder.Items)
That's the Deleted Items folder. Should that be the Inbox folder instead?
Bob
ASKER
That's the Deleted Items folder. Should that be the Inbox folder instead?
yes it should,
so whatever we have there which has been replied and no attachments will be binned
yes it should,
so whatever we have there which has been replied and no attachments will be binned
ASKER
so of each msg in the sent folder which has been replied to and has no attachements wh can been. thats what am
trying to accomplish.
so changed foreach (MailItem msg in oDeletedFolder.Items)
to
foreach
(MailItem msg in oSentFolder.Items)
private static bool hasBeenSent()
{
bool retval = false;
foreach (MailItem msg in oSentFolder.Items)
if (msg.Sent)
{
retval = true;
break;
}
return retval;
}
trying to accomplish.
so changed foreach (MailItem msg in oDeletedFolder.Items)
to
foreach
(MailItem msg in oSentFolder.Items)
private static bool hasBeenSent()
{
bool retval = false;
foreach (MailItem msg in oSentFolder.Items)
if (msg.Sent)
{
retval = true;
break;
}
return retval;
}
ASKER
still there
Yes, I am, but I can't find any way of determining whether a MailItem has been replied to or not, and I am doing research, along with the rest of the tasks that I have to accomplish for myself.
Bob
Bob
ASKER
okay, thanks. Am trying other things as well
ASKER
probably has a sent method
The only way that you can tell if a message has been replied to is to examine the PR_LAST_VERB_EXECUTED property in CDO, since this property is not exposed through the Outlook Automation model, as far as I can tell. This property doesn't keep track of each verb--it is the last action performed.
Bob
Bob
ASKER
hi,
i fink ConservationIndex will do the trick.
if its a replied msg the ConservationIndex will be greater than the original sent item.
i fink ConservationIndex will do the trick.
if its a replied msg the ConservationIndex will be greater than the original sent item.
ASKER
i used this.
and i inserted a break point to find the values of ConservationIndex
using System;
using Microsoft.Office.Interop.O utlook;
using System.Collections;
namespace EmailSorter
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Loader
{
/// <summary>
/// The main entry point for the application.
/// </summary>
private static Application oApp;
private static NameSpace oNS;
private static Recipient oUser;
private static MAPIFolder oFolder;
private static MAPIFolder oReadNotActionedDestinatio nFolder;
private static MAPIFolder oReadDestinationFolder;
private static MAPIFolder oSentFolder;
private static MAPIFolder oSendToBinFolder;
[STAThread]
static void Main(string[] args)
{
Console.WriteLine("KPMG outlook inbox manager");
Console.WriteLine(" In progress");
Console.WriteLine(" Loading outlook folders");
inistialiseFolders();
//MailItem oMsg = (MailItem)oItems.GetFirst( );
int iCount = 0;
int iNewCount = 1;
Console.WriteLine(" Processing mail items");
while (iCount != iNewCount)
{
Items oItems = oFolder.Items;
iCount = oItems.Count;
for (int i=1; i<=iCount; i++)
{
try
{
MailItem oMsg = (MailItem)oItems[i];
string test = oMsg.CC;
string index = oMsg.ConversationIndex;
string topic =oMsg.ConversationTopic;
Console.WriteLine(" Mail item: " + oMsg.Subject);
if (!oMsg.UnRead && hasBeenActioned(oMsg.Subje ct))
{
oMsg.Move(oReadDestination Folder);
Console.WriteLine(" moved to junk folder");
}
if (!oMsg.Sent && hasBeenSent())
{
oMsg.Move(oSendToBinFolder );
Console.WriteLine(" Moved to Deleted Items");
}
// if (!oMsg.UnRead && hasBeenSent(oMsg.Subject))
// {
// oMsg.Move(oSendToBinFolder );
// Console.WriteLine(" Moved to Deleted Items");
// }
//
if (!oMsg.UnRead)
{
oMsg.Move(oReadNotActioned Destinatio nFolder);
Console.WriteLine(" task created");
}
else
{
Console.WriteLine(" not touched");
}
}
catch (System.InvalidCastExcepti on ice)
{
Console.WriteLine(" Not an item of mail");
}
catch {}
}
iNewCount = oItems.Count;
}
Console.WriteLine("Complet ed");
Console.WriteLine("Press enter to exit application");
Console.Read();
}
private static bool hasBeenActioned (string mailSubject)
{
bool retval = false;
for (int i=1; i<=oSentFolder.Items.Count && retval==false; i++)
{
try
{
MailItem msg = (MailItem)oSentFolder.Item s[i];
if (msg.Subject == mailSubject)
{
retval = true;
}
}
catch{}
}
return retval;
}
// private static bool hasBeenSent (string MailSent)
// {
// bool retval = false;
// foreach (MailItem msg in oSendToBinFolder.Items)
// if (msg.Subject == MailSent)
// {
// retval = true;
// break;
// }
//
// return retval;
// }
//
private static bool hasBeenSent()
{
bool retval = false;
foreach (MailItem msg in oSentFolder.Items)
if (msg.Sent)
{
retval = true;
break;
}
return retval;
}
private static ArrayList GetEmailsWithAttachments(M APIFolder folder)
{
ArrayList list = new ArrayList();
foreach (MailItem msg in folder.Items)
if (msg.Attachments.Count > 0)
list.Add(msg);
return list;
}
private static void inistialiseFolders()
{
oApp = new ApplicationClass();
oNS = oApp.GetNamespace("MAPI");
// oUser = oNS.CreateRecipient("Escot t, Robert");
oUser = oNS.CreateRecipient("Azunm a, Chi");
oFolder = oNS.GetSharedDefaultFolder (oUser, OlDefaultFolders.olFolderI nbox);
oReadNotActionedDestinatio nFolder = oNS.GetSharedDefaultFolder (oUser, OlDefaultFolders.olFolderT asks);
oReadDestinationFolder = oNS.GetSharedDefaultFolder (oUser, OlDefaultFolders.olFolderJ unk);
oSentFolder = oNS.GetDefaultFolder(OlDef aultFolder s.olFolder SentMail);
oSendToBinFolder = oNS.GetDefaultFolder(OlDef aultFolder s.olFolder DeletedIte ms);
}
}
}
and i inserted a break point to find the values of ConservationIndex
using System;
using Microsoft.Office.Interop.O
using System.Collections;
namespace EmailSorter
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Loader
{
/// <summary>
/// The main entry point for the application.
/// </summary>
private static Application oApp;
private static NameSpace oNS;
private static Recipient oUser;
private static MAPIFolder oFolder;
private static MAPIFolder oReadNotActionedDestinatio
private static MAPIFolder oReadDestinationFolder;
private static MAPIFolder oSentFolder;
private static MAPIFolder oSendToBinFolder;
[STAThread]
static void Main(string[] args)
{
Console.WriteLine("KPMG outlook inbox manager");
Console.WriteLine(" In progress");
Console.WriteLine(" Loading outlook folders");
inistialiseFolders();
//MailItem oMsg = (MailItem)oItems.GetFirst(
int iCount = 0;
int iNewCount = 1;
Console.WriteLine(" Processing mail items");
while (iCount != iNewCount)
{
Items oItems = oFolder.Items;
iCount = oItems.Count;
for (int i=1; i<=iCount; i++)
{
try
{
MailItem oMsg = (MailItem)oItems[i];
string test = oMsg.CC;
string index = oMsg.ConversationIndex;
string topic =oMsg.ConversationTopic;
Console.WriteLine(" Mail item: " + oMsg.Subject);
if (!oMsg.UnRead && hasBeenActioned(oMsg.Subje
{
oMsg.Move(oReadDestination
Console.WriteLine(" moved to junk folder");
}
if (!oMsg.Sent && hasBeenSent())
{
oMsg.Move(oSendToBinFolder
Console.WriteLine(" Moved to Deleted Items");
}
// if (!oMsg.UnRead && hasBeenSent(oMsg.Subject))
// {
// oMsg.Move(oSendToBinFolder
// Console.WriteLine(" Moved to Deleted Items");
// }
//
if (!oMsg.UnRead)
{
oMsg.Move(oReadNotActioned
Console.WriteLine(" task created");
}
else
{
Console.WriteLine(" not touched");
}
}
catch (System.InvalidCastExcepti
{
Console.WriteLine(" Not an item of mail");
}
catch {}
}
iNewCount = oItems.Count;
}
Console.WriteLine("Complet
Console.WriteLine("Press enter to exit application");
Console.Read();
}
private static bool hasBeenActioned (string mailSubject)
{
bool retval = false;
for (int i=1; i<=oSentFolder.Items.Count
{
try
{
MailItem msg = (MailItem)oSentFolder.Item
if (msg.Subject == mailSubject)
{
retval = true;
}
}
catch{}
}
return retval;
}
// private static bool hasBeenSent (string MailSent)
// {
// bool retval = false;
// foreach (MailItem msg in oSendToBinFolder.Items)
// if (msg.Subject == MailSent)
// {
// retval = true;
// break;
// }
//
// return retval;
// }
//
private static bool hasBeenSent()
{
bool retval = false;
foreach (MailItem msg in oSentFolder.Items)
if (msg.Sent)
{
retval = true;
break;
}
return retval;
}
private static ArrayList GetEmailsWithAttachments(M
{
ArrayList list = new ArrayList();
foreach (MailItem msg in folder.Items)
if (msg.Attachments.Count > 0)
list.Add(msg);
return list;
}
private static void inistialiseFolders()
{
oApp = new ApplicationClass();
oNS = oApp.GetNamespace("MAPI");
// oUser = oNS.CreateRecipient("Escot
oUser = oNS.CreateRecipient("Azunm
oFolder = oNS.GetSharedDefaultFolder
oReadNotActionedDestinatio
oReadDestinationFolder = oNS.GetSharedDefaultFolder
oSentFolder = oNS.GetDefaultFolder(OlDef
oSendToBinFolder = oNS.GetDefaultFolder(OlDef
}
}
}
And did it work? Does it work for messages that we forwarded, but not replied to?
Bob
Bob
ASKER
it has worked yet.
i need to write one of these
private static bool hasBeenSent()
{
bool retval = false;
foreach (MailItem msg in oSentFolder.Items)
if (msg.Sent)
{
retval = true;
break;
}
return retval;
}
to evaluate if a msg is replied or forwarded
i need to write one of these
private static bool hasBeenSent()
{
bool retval = false;
foreach (MailItem msg in oSentFolder.Items)
if (msg.Sent)
{
retval = true;
break;
}
return retval;
}
to evaluate if a msg is replied or forwarded
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks bob, will try this code on monday.
ASKER
hi bob, am more focused now i shall close this and will ask the question again.
thanks
thanks
private static bool hasBeenSent()
{
bool retval = false;
foreach (MailItem msg in oDeletedFolder.Items)
if (msg.Sent)
retval = true;
return retval;
}
Now, you want to find email messages that don't have attachments (msg.Attachments.Count > 0)?
What version of Outlook are you using (I have 2003)?
Bob