-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
An invalid character was found in the mail header: ';' #332
Comments
Do you have the stack trace of this exception and/or small code sample to reproduce? |
You said that you "received an e-mail". Does this mean you are using the |
If that's the case and you are indeed parsing an inbound email, can you share the JSON payload sent to you by SendGrid to help me reproduce the problem? |
Out of curiosity, I ran a quick little test to see if Microsoft's own email address parsing will accept such an email address: var rawEmailAddress = "Undisclosed recipients:;";
var parsedAddress = new System.Net.Mail.MailAddress(rawEmailAddress); When I run this test, I get If I remove the semi-colon, I get var rawEmailAddress = "Undisclosed recipients:";
var parsedAddress = new System.Net.Mail.MailAddress(rawEmailAddress); If I remove both the semi-colon and the colon I get var rawEmailAddress = "Undisclosed recipients";
var parsedAddress = new System.Net.Mail.MailAddress(rawEmailAddress); So it seems to me that the address in your scenario is hopelessly malformed and it's not clear to me at this point what StrongGrid could do to resolve this issue. |
I'll send you the total payload tomorrow morning. And I agree, the format
in this field is not valid. But if it comes from exchange and an outlook
client, it should maybe be fixed.
man. 29. jun. 2020, 16:09 skrev Jericho <notifications@github.com>:
… Out of curiosity, I ran a quick little test to see if Microsoft's own
email address parsing will accept such an email address:
var rawEmailAddress = "Undisclosed recipients:;";var parsedAddress = new System.Net.Mail.MailAddress(rawEmailAddress);
When I run this test, I get An invalid character was found in the mail
header: ';' exception you mentioned.
If I remove the semi-colon, I get An invalid character was found in the
mail header: ':'.
var rawEmailAddress = "Undisclosed recipients:";var parsedAddress = new System.Net.Mail.MailAddress(rawEmailAddress);
If I remove both the semi-colon and the colon I get The specified string
is not in the form required for an e-mail address.
var rawEmailAddress = "Undisclosed recipients";var parsedAddress = new System.Net.Mail.MailAddress(rawEmailAddress);
So it seems to me that the address in your scenario is hopelessly
malformed and it's not clear to me at this point what StrongGrid could do
to resolve this issue.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#332 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACYJSYPED4QBDKNS2DYTROTRZCOCJANCNFSM4OLAKVGA>
.
|
When you say it should be fixed, what's your expectation? How do you propose StrongGrid should handle this scenario? |
The whole header is:
And I agree I'm not sure if StrongGrid should handle this. The only solution to handle this is just to swallow the exception and ignore errors from the System.Net.Mail.MailAddress-method, which may not be good. It seems that the mail that is originally is a newsletter with all the recipients in the BCC-field. I'm not sure if they have sent it through a newsletter-program or via outlook. Anyhow the mails received in this format does not have any value for us, so if the parsing fails due to this, it will just generate a parse error. Thanks for your time! :) |
Here is the current StrongGrid logic: var parsedAddress = new System.Net.Mail.MailAddress(rawEmailAddress);
return new MailAddress(parsedAddress.Address, parsedAddress.DisplayName); As you can see, we delegate the parsing of email addresses to System.Net.Mail.MailAddress to figure out the Thinking out loud: maybe we could ignore parsing exceptions and use a null value in lieu of try
{
var parsedAddress = new System.Net.Mail.MailAddress(rawEmailAddress);
return new MailAddress(parsedAddress.Address, parsedAddress.DisplayName);
}
catch
{
return new MailAddress(null, rawEmailAddress);
} I'm not totally sold on this idea though. We need to think further on the possible ramifications (if any) of the MailAddress with a null |
I will ad this logic to the upcoming release. |
🎉 This issue has been resolved in version 0.73.0 🎉 The release is available on: Your GitReleaseManager bot 📦🚀 |
I received an e-mail with the following item in the header:
To: Undisclosed recipients:;
It fails with the error message:
An invalid character was found in the mail header: ';'
It looks like the e-mail is sent through Outlook / Exchange
The text was updated successfully, but these errors were encountered: