Loading MailMessage using MapiMessage.FromMailMessage throws "Email not valid" exception even though email addresses are valid

I am getting an “Email address is not valid” exception trying to load a MailMessage object into a MapiMessage object even though all included email addresses within the MailMessage appear to be valid. I have attached a sample document.

Email_Address_Not_Valid_Sample.zip (21.1 KB)

The stripped down
code I’m executing is

using (MailMessage msg = MailMessage.Load(process_result.ProcessedFileName))
    {
        MapiConversionOptions mco = MapiConversionOptions.UnicodeFormat;
        mco.PreserveEmptyDates = true;
        using (MapiMessage mapiMessage = MapiMessage.FromMailMessage(msg, mco))
        {
        }
    }

The error is occuring here:

at Aspose.Email.Mapi.MapiElectronicAddress.set_EmailAddress(String value)
at BW.c()
at BW.BWiFd()
at Aspose.Email.Mapi.MapiMessage.d(b4 d, OutlookMessageFormat v, String c, Int32 t)
at Aspose.Email.Mapi.MapiMessage.n(MailMessage d, MapiConversionOptions v)
at Aspose.Email.Mapi.MapiMessage.FromMailMessage(MailMessage message, MapiConversionOptions options)
at NativeViewDocumentConverterAsposeMsg.d__9.MoveNext()

@skowald

Summary
MapiMessage.FromMailMessage throws “Email address is not valid” when the source MailMessage (or EML file) contains malformed MIME parts or header formatting issues, even if the address strings look correct.

Why it happens
The Aspose.Email parser validates the full MIME structure of the message. Problems such as a missing boundary parameter, duplicate boundary strings, malformed Content‑Type headers, improperly quoted display names, or stray characters in From/To/Cc/Bcc headers cause the parser to treat the message as invalid and raise the generic “Email address is not valid” exception. Well‑formed messages convert without error.

What to do next

  1. Inspect the original EML/MailMessage
  • Open the raw file in a text editor.
  • Look for Content-Type: multipart/... lines without a boundary= parameter, duplicate boundary values, or missing closing brackets in address headers (e.g., John Doe <john@example.com).
  • Check for unexpected line‑breaks or stray characters in the From, To, Cc, or Bcc headers.
  • Optionally run the file through an RFC‑822/RFC‑2045 validator to spot format violations.
  1. Test with a minimal, well‑formed message
using (var simpleMsg = new MailMessage())
{
simpleMsg.From = new MailAddress("sender@example.com");
simpleMsg.To.Add("receiver@example.com");
simpleMsg.Subject = "Test";
simpleMsg.Body = "Hello";

var mco = MapiConversionOptions.UnicodeFormat;
mco.PreserveEmptyDates = true;

using (var mapi = MapiMessage.FromMailMessage(simpleMsg, mco))
{
// Should succeed if the API works correctly.
}
}

If this succeeds, the issue is specific to the original message.

  1. Collect diagnostic information
  • Full exception stack trace (including any inner exceptions).
  • .NET runtime version and target framework.
  • A sanitized copy of the problematic EML (remove personal data).
  1. Contact Aspose support
    Provide the SDK version you are using, the diagnostic details above, and the problematic email file. The support team can reproduce the issue and advise on any required fixes or work‑arounds.

These steps should help you identify the malformed part of the email and determine whether correcting the source message resolves the exception.

:warning: I could not fully verify this explanation against the retrieved sources. Please double-check the behaviour in your environment and confirm the exact SDK/version.

Hello @skowald,

In the original MSG, the addresses are stored in Exchange (X.500-style) format. The source item is actually a task message (IPM.Task). When such an item is loaded into a MailMessage, Aspose.Email converts it into a MIME message. This means a MIME structure is created with an alternate view of type VTODO.

Inside the VTODO section, all addresses are copied exactly as they appear in the original Exchange message. Because of that, when the MIME content is later converted back into a MapiMessage, the lib encounters these unresolved Exchange-style addresses in VTODO and throws the exception.

Also, it’s not clear why the message is first loaded into MailMessage and then converted back to MapiMessage. This additional round-trip through MIME format is unnecessary for MSG files and is the reason the error occurs.

Instead, you can load the file directly as MapiMessage:

using (MapiMessage mapiMessage = MapiMessage.Load(process_result.ProcessedFileName))
{
}

This avoids the extra conversions and prevents the exception from being thrown.

Thank you.