You have to retrieve the mail message using GetMailMessage() method of your Imap or Pop3 client object (see the following tutorial http://www.rebex.net/mail.net/tutorial-imap.aspx#downloading for more information).
The MailMessage
class has a property Attachments
with collection of message's attachemnts.
Each Attachment
has a GetContentLength()
method, returning length of the attachment in bytes.
Here is a complete sample how to retrieve size of all attachment of individual mail message on IMAP server:
// create client, connect and log in
Imap client = new Imap();
client.Connect("imap.example.com");
client.Login("username", "password");
// select working folder
client.SelectFolder("Inbox");
// get the topmost MailMessage in the folder
MailMessage message = client.GetMailMessage(client.CurrentFolder.TotalMessageCount);
// show count of message attachments
Console.WriteLine("Subject: {0} [{1} attachaments]", message.Subject, message.Attachments.Count);
// show name and size of each attachment
foreach (Attachment attachment in message.Attachments)
Console.WriteLine("\t{0} ({1}KB)", attachment.FileName, attachment.GetContentLength() / 1024);