We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Using Aggregate on MailAddressCollection throws exception

I use the following code to combine all display names and email addresse from the MailAddressCollection CC into a single string.

                    if ((message.CC != null) && (message.CC.Count > 0))
                        inbox.CC = message.CC.Aggregate((x, y) => x + ", " + y).ToString();

One of the MailAdresses OriginalAddressString has the following value

“John, Van Hellsing” <foo@bar.com>

Cause for the problem seems to be the comma.
When the Aggregate method is called, this then throws the following exception:

The specified string is not in the form required for an e-mail address.
   at Aspose.Email.MailAddress.#=zEtDcKLPeOxHa0vQG9xX5tDQ=(String #=zPUIxLQM=)
   at Aspose.Email.MailAddress.#=zMPD5HAs=(String #=zx2x2eO0=)
   at Aspose.Email.MailAddress.#=zk9FSvr2kY7MejzYoZA==(String #=zx2x2eO0=)
   at Aspose.Email.MailAddress..ctor(String address, String displayName, Encoding displayNameEncoding)
   at Aspose.Email.MailAddress.op_Implicit(String address)
   at AsposeImapTest.Program.<>c.<MailsToFwkInboxes>b__1_0(MailAddress x, MailAddress y) in C:\AsposeImapTest\Program.cs:line 142
   at System.Linq.Enumerable.Aggregate[TSource](IEnumerable`1 source, Func`3 func)
   at AsposeImapTest.Program.MailsToFwkInboxes(MailMessage mailmessage) in C:\AsposeImapTest\Program.cs:line 142
   at AsposeImapTest.Program.Main(String[] args) in C:\AsposeImapTest\Program.cs:line 52

Is there anything for me to do in order to avoid this exception?

@manuelk,

I have observed the requirements and the issue shared by you. I request you to please share the working sample cod along with sample message reproducing the issue that we may use on our end to investigate and help you further.