danielcrenna/postmark-dotnet — Issue #14: Message validation fails when recipient DisplayName contains commas
Author: aardila
Created: 2012-01-30 11:37:48+00:00
State: open

To reproduce the issue:

1. Instantiate a `System.Net.Mail.MailAddress` with a display name, i.e. `new MailMessage("john@thesmiths.com", "John Smith, Jr.")`
2. Instantiate a PostmarkMessage passing the `MailMessage` to the ctor.
3. Attempt to send the message through a `PostmarkClient`.
4. An ValidationException is thrown with the message "The provided recipient address 'John Smith' is not valid.

Recipient names can sometimes contain a comma, as in "John Smith, Jr" or "The Smiths, Inc."

While `MailMessage` uses an array of `MailAddress` objects for recipients, `PostmarkMessage` uses a string property to store recipients as comma-separated values. Since the validation attempts to extract recipients by splitting this string using the comma as separator, the tokens returned when the display name contains a coma are not as expected (e.g. "John Smith" and "Jr john@thesmiths.com"). Validation therefore fails as there is no valid email address in the first token.

Stack trace:
at PostmarkDotNet.PostmarkClient.ValidatePostmarkMessage(PostmarkMessage message) in [...]\postmark-dotnet\src\Postmark\PostmarkClient.cs:line 496
at PostmarkDotNet.PostmarkClient.SendMessage(PostmarkMessage message) in [...]\postmark-dotnet\src\Postmark\PostmarkClient.cs:line 129