Sendgrid-csharp: Email.To.Name containing comma causes problem

Created on 9 Jul 2016  路  14Comments  路  Source: sendgrid/sendgrid-csharp

Issue Summary

When I create Email with Name that is Last, First, it gets thru the SendGrid ok, but then SendGrid drops it. The Json that is created by Mail.Get() looks correct, so I think the problem is in the webApi handler on the server side.

Steps to Reproduce

Send message that has a recipient with name that has a comma in it.
SendGrid will drop it for having an invalid address

Technical details:

var msg = new Mail(new Email("[email protected]"), "Test", new Email("[email protected]", "Last, First"), new Content("text/plain", "Testing 1-2-3"));
var request = new SendGrid.SendGridAPIClient(ApiKey);
request.client.mail.send.post(requestBody: msg.Get());

It sends ok, but now if you go check in SendGrid then you will see that SendGrid drops the email for having a bad address, and it appears to be using part of the name as the address...instead of the actual address.

  • sendgrid-csharp Version: 7.0.5
  • .NET Version: 4.5.2
non-library issue

Most helpful comment

This is still an issue as of October 5th 2017.
Surrounding the name with double quotes is a terrible workaround that will display double quotes on the email client.
The "FROM" can have a comma, but the "TO" cannot.

More than a year and this bug is not fixed and marked as closed.

All 14 comments

@APM3,

This is an issue server side. This may be a temporary fix for you: http://stackoverflow.com/questions/30267595/smtpclient-send-with-valid-email-address-that-has-a-comma-in-it

Thanks!

This is still an issue as of October 5th 2017.
Surrounding the name with double quotes is a terrible workaround that will display double quotes on the email client.
The "FROM" can have a comma, but the "TO" cannot.

More than a year and this bug is not fixed and marked as closed.

Hi @jsgoupil,

I've passed along your vote to our product team on this one. I'm not sure why I closed this issue, but a similar issue exists in some of our other repos and the product team does have a fix scheduled on the backlog. Your vote helps bump the priority, so thanks for taking the time to provide feedback!

With Best Regards,

Elmer

Hey @thinkingserious, any update on this? We just spent a whole day investigating why a recipient name containing a comma was processed successfully but dropped because it parsed it incorrectly and used part of it as the email. Thanks!

Hello @jgyllen,

I know this issue is on the product teams radar and a fix should happen at some point.

Would you mind reporting your issue using the feedback blue button at SendGrid.com? Queries from customers directly help increase the priority.

Thanks!

With Best Regards,

Elmer

This still exists and caused problems to all our customers having comma in company name. Is there any time-frame for resolving this? This is a deal breaker for us since users don't want to change company names.

Hello @velja,

I don't have a firm time frame, but I've added your vote to the issue to help increase priority.

In the meantime, someone implemented this patch in PHP, you may be able to create a fix based on the same concept in Node.js.

With Best Regards,

Elmer

Sendgrid also doesn't quote @ characters in mailboxes properly. This leads to

msg.AddTo(new EmailAddress("[email protected]", "[email protected]"))

generating an invalid to header:

To: [email protected] foo@bar.com

the name portion ([email protected]) is invalid according to RFC2822 -- it may not contain @.

While this may appear to be cosmetic it causes deliverability issues, e.g. in exim (with a largely default configuration), header validation is enabled:

2018-10-31 15:43:09 1g0000-000000-LG H=o1.f.az.sendgrid.net [208.117.55.132] X=TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256 CV=no F=foo@bar.com\n may not follow [email protected] : failing address in "To:" header is: [email protected] foo@bar.com"

The workaround here is the same -- manual quoting of the name is required.

Unfortunately I too just wasted a whole afternoon tracking down with this precise issue, and it seems crazy it's not yet been dealt with after 3 years.

My suggestion is to simply check for names that have a comma in them, and if they are not quoted, then quote them. Simple fix would have saved me, and others so very many hours of work, and the thousands of people wouldn't have their emails silently dropped for such a silly reason.

Would adding double quotes around the value of the Name attribute in the EmailAddress class solve this?

https://github.com/sendgrid/sendgrid-csharp/blob/57acb4db07d727d11463d36c24c27568666f2aff/src/SendGrid/Helpers/Mail/Model/EmailAddress.cs#L28-L32

-this.Name = name;
+this.Name = '"' + name+ '"';

.NET normalizes the string.
https://github.com/dotnet/corefx/blob/master/src/System.Net.Mail/src/System/Net/Mail/MailAddress.cs#L79
https://github.com/dotnet/corefx/blob/master/src/Common/src/System/Net/Mail/MailAddressParser.cs#L314

It would probably be best to accept the MailAddress class from .NET as a parameter instead of an own EmailAddress class, then read the DisplayName property from the .NET MailAddress class to internally create the EmailAddress class used for JSON serialization.

We also wasted a full evening tracking down this issue. It has been 4 years since this was reported. Sengrid team, could you please either solve this issue or make it more visible so other people won't wast time on this?

Closing as this was marked as a non-library issue.

After further investigation, I'm reopening this issue and marking it as a bug. This issue has been added to our internal backlog to be prioritized. +1 on the original issue description and PRs will help move it up the backlog.

This issue has been resolved in the backend. Closing out.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

LorenDorez picture LorenDorez  路  4Comments

ivivanov picture ivivanov  路  3Comments

kquinbar picture kquinbar  路  4Comments

shoter picture shoter  路  4Comments

lebamb2 picture lebamb2  路  4Comments