Hi,
I’m fetching messages from an Exchange Server mailbox. This works fine as long as the size of the messages (their attachments) is not too big.
Recently I had to process a message of approx. 100Mb in size, which failed, resulting in a OutOfMemoryException (see attached file for stacktrace).
I’m using the following code:
—
NetworkCredential credential = new NetworkCredential(, , );
IEWSClient client = EWSClient.GetEWSClient(, credential);
ExchangeMessageInfoCollection msgs = client.ListMessages(client.MailboxInfo.InboxUri, true);
foreach (ExchangeMessageInfo msgInfo in msgs)
{
try
{
MailMessage msg = client.FetchMessage(msgInfo.UniqueUri);
}
catch (OutOfMemoryException e)
{
logger.error(e.ToString());
}
}
—
Question is how to process such large messages.
Hi Scheu,
Hi,
I know, normally this should not be the case, but it’s a requirement from our customers in this case.
Unfortunately, it is not possible/allowed for me to setup such an account, but here’s the way I managed to get a 100MB mail on to Exchange Server (since such large attachments are forbidden here as well).
First I created the mail manually with the following code:
—
MailMessage m = new MailMessage();
m.From = "me@domain.com";
m.To = "me@domain.com";
m.Subject = “A big file”;
m.TextBody = “this contains a big file”;
m.Attachments.Add(new Attachment(@"<path to 100mb file>"));
m.Save(@".msg", MailMessageSaveType.OutlookMessageFormatUnicode);
—
Then I dragged the MSG-File into my Outlook mailbox manually (took some time to upload).
After that I could run the code from the original post, which then led to the described problem.
Could you give that a try as well?
Thanks in advance
Scheu
Hi Scheu,
Hi Scheu,
Hi,
yes I updated to Version 3.5.0 of Aspose.Email .NET some days ago.
<!–[if gte mso 9]>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:HyphenationZone>21</w:HyphenationZone>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>DE</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:DontVertAlignCellWithSp/>
<w:DontBreakConstrainedForcedTables/>
<w:DontVertAlignInTxbx/>
<w:Word11KerningPairs/>
<w:CachedColBalance/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
<m:mathPr>
<m:mathFont m:val=“Cambria Math”/>
<m:brkBin m:val=“before”/>
<m:brkBinSub m:val="–"/>
<m:smallFrac m:val=“off”/>
<m:dispDef/>
<m:lMargin m:val=“0”/>
<m:rMargin m:val=“0”/>
<m:defJc m:val=“centerGroup”/>
<m:wrapIndent m:val=“1440”/>
<m:intLim m:val=“subSup”/>
<m:naryLim m:val=“undOvr”/>
</m:mathPr></w:WordDocument>
<![endif]–><span style=“font-size:12.0pt;font-family:“Times New Roman”,“serif”;
mso-fareast-font-family:“Times New Roman”;color:black;mso-ansi-language:DE;
mso-fareast-language:DE;mso-bidi-language:AR-SA”>We use Microsoft Exchange Server 2007
SP3 (8.3.83.0 or higher<!–[if gte mso 10]>
<![endif]–>) but our customers use the 2010 version and have the same issue.
Perhaps this helps for further investigation. When I’m fetching the big message (which takes quite some time before OutOfMemory exception occurs), I can observe (in Task Manager) the memory usage of my test application rising to about 400 to 500MB (or higher). But this should be no problem, I got 16GB of memory available.
Hope this helps.
Thanks for your efforts so far.
Scheu
Hi Scheu,
Hi,
just tested with a sample message containing two 48MB files, which doesn’t work either.
Did you use the code I provided in the original post to fetch the email? Simply to make sure, there’s no difference.
Is it possible for you to test on Exchange Server 2007, just to be sure that it works for you like with 2010/2013?
Thanks.
Scheu
Hi Scheu,
Yes, I have used the same code as you shared in your first post. Please spare us a little time to prepare and test this issue with Exchange Server 2007 as well. I’ll return to you on this as soon as I am done with testing this issue at my end and appreciate your patience in this regard.
Hi,
is there any new insight in this regard? I have to ask because this is kind of pressing.
Thanks.
Scheu
Hi Scheu,
Hi,
unfortunately, that is not possible, as I mentioned in an earlier post.
Since we both used the same code and the same version of Aspose, perhaps the system makes a difference. Could you tell me your system specs, operating system and so on?
Besides, I found out that now streaming a message is possible, which wasn’t available in prior versions of Aspose. Consider the following code:
—
NetworkCredential credential = new NetworkCredential(, , );
IEWSClient client = EWSClient.GetEWSClient(, credential);
ExchangeMessageInfoCollection msgs = client.ListMessages(client.MailboxInfo.InboxUri, true);
foreach (ExchangeMessageInfo msgInfo in msgs)
{
try
{
using (var stream = new System.IO.FileStream(@“myMessage.msg”, FileMode.Create))
{
client.SaveMessage(msgInfo.UniqueUri, stream);
stream.Close();
}
}
catch (OutOfMemoryException e)
{
logger.error(e.ToString());
}
}
—
I assumed, this would work, but instead of starting to write to disk immediately, this method does exactly the same like the original one, namely allocating the whole message in memory, which then leads to the same OutOfMemory exception.
Any ideas on this approach?
Thanks.
Scheu
Hi Scheu,
Hi Scheu,
The issues you have found earlier (filed as NETWORKNET-34182) have been fixed in this update.
This message was posted using Notification2Forum from Downloads module by Aspose Notifier.
Hi,
I’m afraid to say that on my end nothing changed with the new version 3.7.0
I’m just wondering if you were able to reproduce my exact same problem, since you didn’t seem to be able to at the beginning.
Could you please tell me, what has been changed and how that was tested exactly.
So, for testing, did you use an email with an attached file of a 100mb in size and did you save it as a msg file using a stream or not, since in my client neither works.
best regards
Scheu
Hi Scheu,
- Please share your system details with us i.e. Operating System version (32/64 bit), installed Memory size.
- Please provide us again the exact sample code that raises this issue.
- Please provide us the complete stack trace of the issue
- Also, please point out the exact line of code that raises this exception.
At my end, using 64-bit Windows 7 OS, I am unable to observe this issue now with the latest version of Aspose.Email for .NET 3.7.0. Your answers to the above queries will help us assist you further.
Hi,
1. 64-bit Windows 7 OS, 16Gb of RAM, Core i5
2. Two possibilities, but neither works:
a. Non-streaming:
NetworkCredential credential = new NetworkCredential(uname, pw, dom);
IEWSClient client = EWSClient.GetEWSClient(uri, credential);
ExchangeMessageInfoCollection msgs = client.ListMessages(client.MailboxInfo.InboxUri, true);
foreach (ExchangeMessageInfo msgInfo in msgs)
{
try
{
MailMessage msg = client.FetchMessage(msgInfo.UniqueUri);
}
catch (Exception e)
{
…
}
}
b. using streaming:
NetworkCredential credential = new NetworkCredential(uname, pw, dom);
IEWSClient client = EWSClient.GetEWSClient(uri, credential);
ExchangeMessageInfoCollection msgs = client.ListMessages(client.MailboxInfo.InboxUri, true);
foreach (ExchangeMessageInfo msgInfo in msgs)
{
try
{
using (var stream = new System.IO.FileStream(@“myMessage.msg”, FileMode.Create))
{
client.SaveMessage(msgInfo.UniqueUri, stream);
stream.Close();
}
}
catch (OutOfMemoryException e)
{
…
}
}
3. Stacktrace:
14.01.2014 09:45:42 - 7152: [ERR] System.OutOfMemoryException: Eine Ausnahme vom Typ “System.OutOfMemoryException” wurde ausgelöst.
bei System.Text.StringBuilder.set_Length(Int32 value)
bei System.Xml.XmlTextReaderImpl.ParseText()
bei System.Xml.XmlTextReaderImpl.ParseElementContent()
bei System.Xml.XmlTextReaderImpl.Read()
bei System.Xml.XmlTextReader.Read()
bei System.Xml.XmlReader.ReadStartElement()
bei Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderExchangeServiceBinding.Read303_MimeContentType(Boolean isNullable, Boolean checkType)
bei Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderExchangeServiceBinding.Read418_MessageType(Boolean isNullable, Boolean checkType)
bei Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderExchangeServiceBinding.Read487_ArrayOfRealItemsType(Boolean isNullable, Boolean checkType)
bei Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderExchangeServiceBinding.Read490_ItemInfoResponseMessageType(Boolean isNullable, Boolean checkType)
bei Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderExchangeServiceBinding.Read678_ArrayOfResponseMessagesType(Boolean isNullable, Boolean checkType)
bei Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderExchangeServiceBinding.Read693_GetItemResponseType(Boolean isNullable, Boolean checkType)
bei Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderExchangeServiceBinding.Read795_GetItemResponse()
bei Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer85.Deserialize(XmlSerializationReader reader)
bei System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
bei System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle)
bei System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
bei System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
bei Aspose.Email.Exchange.Schema.Exchange_2013.ExchangeServiceBinding.GetItem(GetItemType GetItem1)
bei .??.FetchMessage(String )
bei .??.SaveMessage(String , Stream )
4. Either:
a. MailMessage msg = client.FetchMessage(msgInfo.UniqueUri);
b. client.SaveMessage(msgInfo.UniqueUri, stream);
However, there seems to be some misunderstanding which might make a big difference I suppose.
I always spoke of an email with a single file attached, that has the size of about 100MB - not multiple files. That is the case I need to get working.
(but then again, even an email with 6+ attachments like you used, did not work for me)
best regards
Scheu
Hi Scheu,