I want to get the attachment size of a file within a message. I am unable to locate that.

asked 11 May '11, 16:26

Rebex%20KB's gravatar image

Rebex KB ♦♦
258519
accept rate: 63%


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);
link

answered 11 May '11, 16:38

Jan%20Sotola's gravatar image

Jan Sotola ♦♦
3566
accept rate: 36%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×76
×53
×36
×10

Asked: 11 May '11, 16:26

Seen: 529 times

Last updated: 11 May '11, 16:38