Check whether a mail has attachment

Jun 4, 2012 at 2:39 PM

How can we check whether a mail has attachments with it or not?

Jun 4, 2012 at 2:43 PM

MailMessage.Contents ?

Coordinator
Jun 5, 2012 at 12:29 AM

Yes. Contents property represent attached content.
MailContent object has a property IsAttachment.
Please check this property whether this file is attached file or not.

Other way to get MailContent list is to execute MailMessage.GetAttachedContents method return attached MailContent list.

Jun 5, 2012 at 5:15 AM
Edited Jun 5, 2012 at 5:48 AM

IsAttachment is returning false inspite of having attachments in the mail.

MailMessage.GetAttachedContents has 2 arguments: Contents and Predicate. What do I pass in them?

Eg:

HigLabo.Net.Pop3.Pop3Client cl = new HigLabo.Net.Pop3.Pop3Client(); 
//..
//Code 
//..
if (cl.Authenticate() == true)
{
        MailMessage mg = null;
         Int32 mailCount = Convert.ToInt32(cl.GetTotalMessageCount());
         for (int i = 1; i < mailCount + 1; i++)
           {
                  mg = cl.GetMessage(i);
                  List<MailContent> lstAttachment = mg.GetAttachedContents( ??? , ???);
          }
}

MailMessage.Contents is returning Count = 2 irrespective of whether mail has attachment or not. How do I check through it whether mail has an attachment or not?

Jun 5, 2012 at 9:05 AM
Edited Jun 5, 2012 at 9:05 AM

Solved it using GetAttachedContents(MailMessage) method