MailBee. NET Objects Tutorials

Determine if the message has attachments without downloading the entire message

The developer should use HasAttachments property of MailMessage to indicate if the message has attachments:

C#

MailMessageCollection msgs = pop.DownloadMessageHeaders();

foreach (MailMessage msg in msgs)
{
    if (msg.HasAttachments)
    {
        Console.WriteLine("Message #" + msg.IndexOnServer + " has attachment(s)");
    }
}

VB.NET

Dim msgs As MailMessageCollection =  pop.DownloadMessageHeaders() 
 
Dim msg As MailMessage
For Each msg In msgs
    if (msg.HasAttachments) Then
        Console.WriteLine("Message #" + msg.IndexOnServer + " has attachment(s)")
    End If
Next

Note: This property may not be 100% accurate if only the header of the message has been downloaded. The developer should download the entire message to be sure if it really has any attachments or not.