Hi Scott,
Thank you for posting your query.
We have gone through existing samples available in documentation and forum and here are our findings.
- ExchangeMessageInfo.Size property returns the size of the message in bytes
- ImapMessageInfo.Length property returns the size of the message in bytes
This information you can validate from the following tests by appending a sample message and then retreiving it back using Exchange and IMAP clients. For some reason, the PR_MESSAGE_SIZE value is not available for the downloaded messages. However, the values returned by ExchangeMessageInfo.Size and ImapMessageInfo.Length are the same. Please try the following sample code at your end and share your feedback with us.
Code:
public static void GetMessageSizeUsingImap()
{
ImapClient client = GetAsposeEWSImapClient1();
client.SelectFolder(ImapFolderInfo.InBox);
Console.WriteLine("Message size using ImapClient: " + client.ListMessages()[0].Length);
}
public static void GetMessageSizeUsingEWS()
{
IEWSClient client = GetAsposeEWSClient1();
Console.WriteLine("Message size using EWS: " + client.ListMessages(client.MailboxInfo.InboxUri)[0].Size);
MailMessage msg = client.FetchMessage(client.ListMessages(client.MailboxInfo.InboxUri)[0].UniqueUri);
MapiMessage mapiMsg = MapiMessage.FromMailMessage(msg);
if (mapiMsg.Properties[MapiPropertyTag.PR_MESSAGE_SIZE] != null)
Console.WriteLine("PR_MESSAGE_SIZE: " + mapiMsg.Properties[MapiPropertyTag.PR_MESSAGE_SIZE].ToString());
}
public static void AppendMsgToTest4()
{
IEWSClient client = GetAsposeEWSClient1();
MailMessage message = new MailMessage(
"user@domain.com",
"asposeemail.test3@aspose.com",
"EMAILNET-34717 - " + Guid.NewGuid().ToString(),
"EMAILNET-34717 EWS: Can there be any way of retreiving Message size before actually fetching it?");
byte[] data = new byte[1000000];
MemoryStream ms = new MemoryStream(data);
Attachment attachment = new Attachment(ms, "test.txt");
message.Attachments.Add(attachment);
client.AppendMessage(client.MailboxInfo.InboxUri, message);
client.Dispose();
}