I have changed direction on this, solving many of my problems but creating new ones.
If you have used CDO 1.2.1 or MAPI and C# please take a look at my code below.
The purpose of the code (at ths stage) is just to list the email attachments in an inbox using their full names.
Later on I will move them arround accordingly.
Solution 1: Using the MAPI Component
This will only provide a truncated(8.3) attachment file name which does not suit my needs
Code:
label1.Text = string.Empty;
axMAPISession1.DownLoadMail = true;
axMAPISession1.SignOn();
axMAPIMessages1.SessionID = axMAPISession1.SessionID;
axMAPIMessages1.Fetch();
for ( int i=0; i< (int) axMAPIMessages1.MsgCount; i++)
{
axMAPIMessages1.MsgIndex = i;
for (int j=0; j< (int)axMAPIMessages1.AttachmentCount; j++)
{
//List the attachment names
label1.Text += axMAPIMessages1.AttachmentName + "\n";
}
}
axMAPISession1.SignOff();
Solution 2: Using CDO 1.2.1
This can access the full attachment filename (So I'm Told) but I am unable to get it to log in to an exchange inbox.
Code:
MAPI.Session objSession;
MAPI.Folder objFolder ;
MAPI.Messages objMessageList;
MAPI.Message objMessage;
MAPI.Attachments objAttachmentList;
MAPI.Attachment objAttachment;
MAPI.MessageFilter objFilter;
objSession = new MAPI.SessionClass();
// Logon to the Exchange Server using Internet Mail method and profile
objSession.Logon("MYADMINPROFILENAME", "MYADMINPASSWORD", false, false, 0, true, "MYMAILSERVER\nMYADMINPROFILENAME");
objFolder = (MAPI.Folder) objSession.Inbox;
objMessageList = (MAPI.Messages) objFolder.Messages;
//Set filter to get all unread mail
objFilter = (MAPI.MessageFilter) objMessageList.Filter;
objFilter.Unread = true;
objMessage = (MAPI.Message) objMessageList.GetFirst(objFilter);
if((int) objMessageList.Count == 0)//objMessage Is Nothing
{
label2.Text = "No Mail:" + System.DateTime.Now;
}
else //Never made it to here
{
//("You've got mail")
//' Loop until all mail are read
for (int i=0; i<(int)objMessageList.Count; i++)
{
objAttachmentList = (MAPI.Attachments) objMessage.Attachments;
for (int j=0; j<(int)objAttachmentList.Count; j++)
{
objAttachment = (MAPI.Attachment) objAttachmentList.get_Item(j);
//label2.Text += objAttachment.Fields(CdoPR_ATTACH_LONG_FILENAME) + "\n";
label2.Text += objAttachment.Name + "\n";
}
}
}
I am new to c# so please point out the obvious.
I feel the main problem with the CDO 1.2.1 is the logging in.
With the MAPI Component I don't think the full file name is available, please tell me if I am wrong.
PS
No errors are occuring in the code.
It just does not do what I want it to.
Thanks for your time to read my problem
======================================
They say, best men are moulded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================