Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 9th, 2003, 03:43 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default MAPI inbox checker

I am required to create an application that will check a specified email inbox for email attachements.
This is my first adventure into C# although I have built this app in VB6 previously.
I am rebuilding it to learn C# whilst improving the app.
I am having trouble with even the most simple area of logging in the MAPI session object.
Can anyone point me in the direction of a good article of tutorial on this.
I do not wish to rely on 3rd party tools or outlook, just straight to the Exchange server.

At present I have included the session and message components which are of types AxMSMAPI.AxMAPIMessages and AxMSMAPI.AxMAPISession and have instantiated them (I Think!) with the code:

private void btnCheckMail_Click(object sender, System.EventArgs e)
        {
            MAPISession = new AxMSMAPI.AxMAPISession();
            MAPIMessages = new AxMSMAPI.AxMAPIMessages();


        }

I do not know where to go from here, any advise or redirection would be very much appreciated.

Thankyou for your time.

Rod

======================================
They say, best men are moulded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
__________________
======================================
"They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad."
--Shakespeare
======================================
 
Old September 11th, 2003, 03:07 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

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.
======================================





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to read out a inbox mailbox splanky Pro VB.NET 2002/2003 7 October 18th, 2007 07:14 AM
Picking mail from Inbox sanjepau Biztalk 0 July 28th, 2007 08:42 AM
Filtering My Inbox steve-o General .NET 0 September 22nd, 2004 08:07 PM
scan attachments from inbox sv_shali PHP How-To 3 October 25th, 2003 12:40 AM
Watch Exchange Inbox rodmcleay VB How-To 0 July 10th, 2003 12:15 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.