Free Support Forum - aspose.com

Aspose.Mail System.FormatExceptionThe mail header is malformed. Cannot fetch emails at all

Hi Team,

Our program connect with an mailbox and tries to fetch emails to read. Mostly it works fine but
some times it gets this exception and does not fetch any emails at all from this mailbox.
We found it always due to one of the email in the mailbox which it could read. If we take that one email out of mailbox then it works again. So question is why it just explodes on one email which it cannot read - It is just stop the processing of all emails just because of one email. It should be fetching all emails first and then when we loop through these email list and then throwing exception on that particular email. Then Why does one of the email makes such problem? it is a normal email which is read by Outlook very well.

The invalid value ‘System.FormatExceptionThe mail header is malformed. at œ.š.a(String , Int32& , StringBuilder )
at œ.š.(String , Int32& , StringBuilder )
at œ.š.(String data, Int32& offset, String& displayName, Boolean checkAddress)
at œ.š.(String , Int32& , Boolean )
at Aspose.Email.Mail.MailAddressCollection.(String , Boolean )
at .Ÿ•.FetchMessage(String )
at WTS.Mail.AsposeMail.EmailService.GetInboxMails()
at EmailReader.EmailReader.ProcessEmails()
at EmailReader.EmailReader.Start(IEmailService EmailServiceInterface)
at UrlaubTracker.Program.Open()
at UrlaubTracker.Program.Main(String[] args)’ was specified for the ‘Body’ element.
System.FormatExceptionThe mail header is malformed. at œ.š.a(String , Int32& , StringBuilder )
at œ.š.(String , Int32& , StringBuilder )
at œ.š.(String data, Int32& offset, String& displayName, Boolean checkAddress)
at œ.š.(String , Int32& , Boolean )
at Aspose.Email.Mail.MailAddressCollection.(String , Boolean )
at .Ÿ•.FetchMessage(String )
at WTS.Mail.AsposeMail.EmailService.GetInboxMails()
at EmailReader.EmailReader.ProcessEmails()
at EmailReader.EmailReader.Start(IEmailService EmailServiceInterface)
at UrlaubTracker.Program.Open()
at UrlaubTracker.Program.Main(String[] args)

We are using Aspose.Net 4.4 with C#.

I would be thankful for your reply.
Kind regards
Ali Syed

@alisyed,

I have observed your question and suggest you to please first try using latest Aspose.Email for .NET 20.2 on your end. In case there is still an issue then please share the working sample project along with test account credentials reproducing the issue on your end. I hope you must have encapsulated the Message retrieving code in try catch block too and have handled any incurring exception.

Hi @mudassir.fayyaz,

Upgrading cost money. Before we upgrade, we would like to confirm if this error is known and is fixed in version 20.2.

I figured the error is happening on a fetching a single email, not on listing messages from inbox.
Context: The program sends an outlook voting email to a person for a yes and no reply and also parse the responses for this email. We have notice when the reply of thie voting email is through the voting buttons; from Outlook; it works. But if the receiver person replys back with normal Reply button then with this email reply Aspose mail has problem.

The code is like this :

ExchangeMessageInfoCollection msgCollection;
try
{
// Call ListMessages method to list messages info from Inbox
msgCollection = MailClient.ListMessages(Inbox.Uri);

        }
        catch (Exception ex)
        {

            throw ex;
        }
       

        List<IEmail> Emails = new List<IEmail>();

        // Loop through the collection to get Message URI
        foreach (ExchangeMessageInfo msgInfo in msgCollection)
        {
            string strMessageURI = msgInfo.UniqueUri;

            try
            {
                // Now get the message details using FetchMessage()
                MailMessage msg = MailClient.FetchMessage(strMessageURI);

                Email Email = new AsposeMail.Email(msg);
                Email.UniqueUri = strMessageURI;

                Emails.Add(Email);
            }
            catch (Exception)
            {

               
            }
           

        }

        return Emails;

Kind regards
Ali

@alisyed,

Thank you very much for your feedback and narrowing down the issue on your end. You may try Aspose.Email for .NET 20.2 with a 30 days free trial license on your end and see if the latest version is working fine on your end or not. If that is working then you may consider upgrading subscription.

The other option is you may share a sample project privately with me along with test account credentials and I may test that for you using latest version and even log that in our issue tracking system, if latest version prove to have issues.