Sign In  Sign Up Live-Chat

file attachments :names of each attached file

Last post 06-02-2008, 8:48 AM by CINsyg. 6 replies.
Sort Posts: Previous Next
  •  01-02-2007, 3:43 PM 64376

    file attachments :names of each attached file

    please could you provide the code to obtain  the names of each  attached file (for each email in a selected folder for a selected mailbox) using

    a) the imap protocol

    b) the pop3 protocol

    (with of the code to detect if the currently selected email has any attachments)

    ps... it would be very useful if the help file for the product (.aspose.network) provided more examples of how use the product

    thanks

     

     

     
  •  01-04-2007, 3:07 AM 64490 in reply to 64376

    Re: file attachments :names of each attached file

    Dear rickwats,

    Please check it out. Basically, if you want to access any info about an email message, you can get a MailMessage instance firstly. Pop3Client and ImapClient all support to fetch message from server and cast into a MailMessage instance.

    1) for Pop3            

    Pop3Client client = new Pop3Client("localhost", "user", "12345678");
                Pop3MessageInfoCollection infos = null;

                client.Connect(true); //connect to server, and auto login to it
                infos = client.ListMessages(); //list the messages in the server

                if(infos != null)
                {
                    for (int i = 0; i < infos.Count; i++)
                    {
                        MailMessage msg = client.FetchMessage(infos[ i ].SequenceNumber);//fetch message to local
       
                        foreach (Attachment att in msg.Attachments) //enumerate attachments in the message
                        {
                            Console.WriteLine(att.Name + " " + att.MediaType + " " + att.ContentType);
                        }
                    }
                }

    2) for Imap

                ImapClient client2 = new ImapClient("localhost", "testuser", "psw");
                client2.Connect(true); //connect to server, and auto login to it
                client2.SelectFolder("Inbox"); //select the folder
                ImapMessageInfoCollection infos2 = null;
                infos2 = client2.ListMessages(); // list the messages
                if(infos2 != null)
                {
                    for (int i = 0; i < infos2.Count; i++)
                    {
                        MailMessage msg = client2.FetchMessage(infos2[ i ].SequenceNumber); //fetch message to local

                        foreach (Attachment att in msg.Attachments) //enumerate attachements in the message
                        {
                            Console.WriteLine(att.Name + " " + att.MediaType + " " + att.ContentType);
                        }
                    }
                }


    Team Lead
    Aspose Guangzhou Team
    About Us

    Contact Us
     
  •  05-29-2008, 9:27 AM 129237 in reply to 64490

    Re: file attachments :names of each attached file

    Hello, hope someone is still watching this thread.

    If i try to get the attachments to save i loose the names og the attachments when i do this

    foreach (Attachment att in msg.Attachments) //enumerate attachments in the message
    {
                  Console.WriteLine(att.Name);
    }

    If i do a count on the msg.Attachments is shows the correct number of attachments, but the name is always == string.Empty

    Eny Ideers?

    Regards, CIN


     

     
  •  05-29-2008, 3:29 PM 129281 in reply to 129237

    Re: file attachments :names of each attached file

    Hi,

    Could you please attach a sample file for which this is happenning. If you are reading email files after connecting to some mail server, you can save them to your disk by calling MailMessage.Save() method.


    Best Regards,

    Saqib Razzaq
    Support Developer
    Aspose Guangzhou Team

     
  •  05-30-2008, 3:27 AM 129366 in reply to 129281

    Re: file attachments :names of each attached file

    Attachment: Present (inaccessible)

    Thanks for the fast reply

    There is a txt file code snippet attached.

    currentItem is a SharePoint ListItem that is feached onItemAdded event in a DocumentLibrary

    Hope this is sufficeint info, else please let me know.

    I have deployed the Aspose.Network dll to the GAC ? along with my eventhandler

    Regards, CIN

     
  •  06-02-2008, 2:52 AM 129548 in reply to 129366

    Re: file attachments :names of each attached file

    Hi,

    Sorry for the inconvenience. We are looking into this issue.

    As a workaround, could you please try Aspose.Outlook.MapiMessage class. The following code snippet loads a file from disk and iterates through the attachments. You can also call FromStream() method to load the msg file from stream.

    MapiMessage msg = MapiMessage.FromFile("c:\\temp\\sample.msg");

    foreach (MapiAttachment attachment in msg.Attachments)

    {

    Console.WriteLine("File Name: " + attachment.FileName); // 8 character file name + 3 character ext

    Console.WriteLine("LongFile Name: " + attachment.LongFileName); // full file name + 3 char ext

    }


    Best Regards,

    Saqib Razzaq
    Support Developer
    Aspose Guangzhou Team

     
  •  06-02-2008, 8:48 AM 129608 in reply to 129548

    Re: file attachments :names of each attached file

    Thanks.

    The MapiMessage object worked. thow a had to use the FromStream method, as my files is web based.

    using (Stream stream = currentItem.File.OpenBinaryStream())
     {
                            //set to start of stream
                            stream.Seek(0, SeekOrigin.Begin);                      
                            //open the file as mapi message                   
                            MapiMessage msg = MapiMessage.FromStream(stream); ........

     

    Regards, CIN

     
View as RSS news feed in XML