-
Notifications
You must be signed in to change notification settings - Fork 722
Commas in recipient name cause mail to be silently dropped (worked in v2) #291
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
Comments
Add workaround for lack of proper recipient name quoting in SendGrid v3 mail send API. (See sendgrid/sendgrid-python#291.) Only affects recipient display-names -- not from_email or reply_to. Also add (undocumented) setting to disable workaround, if/when SendGrid fixes the bug.
(I see this has also been reported against other SendGrid client libs as sendgrid/sendgrid-csharp#268 and sendgrid/sendgrid-ruby#77.) |
Hi @medmunds, Thank you for taking the time to provide these details! I will pass this along to our product team for possible implementation. With Best Regards, Elmer |
We just got hit by the same error. This is definitely a bug! |
I have added your vote to the issue. |
Just realized I should mention, that we are using the SendGrid Java API client, and not the python one. So the error must be in the SendGrid API not in the client libraries |
You are correct, this is an API level issue and the appropriate PMs are aware of the issue. I have added your vote to that issue for you. Thanks! |
FYI, the workaround suggested in the C# issue seems to work: you can quote the recipient names yourself, before handing off to SendGrid. In Python, you'd want to use email.utils.quote. To/cc/bcc names only -- the API handles from and reply-to names correctly. (Of course, if/when SendGrid fixes the API-side issue, this could result in extra quotes in recipient names until you remove the workaround.) |
Thanks for sharing the work around :) Here is what I recommend as an interim fix ( hopefully someone awesome will create a PR ;) ): sendgrid/sendgrid-php#368 |
hi |
I would like to work on this |
It's, uh... surprising that SendGrid would want to implement separate workarounds in every client library rather than fix the underlying API bug. (The current API behavior suggests that SendGrid's servers may be assembling messages by concatenating raw API input strings, without properly escaping them for use in email headers -- and there are all sorts of things can go wrong with that approach. Plus, all the client-side workarounds will later need to be removed when the API does get fixed.) But having said that, if you do want to add a workaround to sendgrid-python, the goal would be to "clean" the The "cleaning" function could be either:
(I personally think the second approach is better, but that's just my opinion. FWIW, it's what I used in a library I maintain that calls the SendGrid API directly. But I also included a setting to disable this behavior if/when the API gets fixed.) |
@medmunds, agreed that |
we just switched to V3 api from SMTP and found this out too, that commas in the To address name field result in a dropped email. bad.. |
Thanks for taking the time to provide feedback @kirk-quinbar, I have passed along your feedback to our product team. With Best Regards, Elmer |
Closing this as it has been marked a non-library issue. |
This seems to have been fixed at the API level, based on testing on 2024-08-07. (No idea how long ago it changed.) I can't tell if we should count on the fix, because the problem is still mentioned under "Limitations" in SendMail's Mail Send API Overview docs:
(Also, it's unclear where to report issues with SendGrid's API itself or its documentation, which is why they end up reported as library issues like this one.) |
Issue Summary
When sending a message, if a recipient
name
contains a comma, the send appears to succeed but the message ends up with a "dropped" status and is never delivered.The equivalent code worked correctly (successfully delivered the message -- including the comma in the recipient's display-name) with the v2 send API.
I'm aware the v3 send docs indicate you can't include commas or semicolons (or -- erroneously, periods) in recipient names. But there are many legitimate cases where a display-name would include a comma. And since commas are allowed (and work) in the from_email name, it's confusing that the v3 API wouldn't be properly quoting recipient display-names like the v2 API did.
Steps to Reproduce
Test with v3 API:
pip install sendgrid==3.6.3
(current version as of this report) and run this code:Results:
(202, '')
(send accepted; no apparent error)Find the message in your SendGrid activity feed.
Results: The message has been dropped (and displays the confusing email address "mr.craig"):

Expected: The message should have been processed and delivered
Now remove the comma from the
to_email
-- but leave it in thefrom_email
, and send again.Results: Message is processed and delivered, with the comma intact in the
from_email
display-name. (This demonstrates that the v3 API correctly handles commas in names in some cases. So the code to properly escape and quote names must exist somewhere in the v3 API.)Now test with the v2 send API:
pip install sendgrid==2.2.1
(last release using v2 send) and run this code -- the equivalent of the v3 example above:Results: The message is processed and delivered, with the comma in the recipient's display-name intact. The activity feed confirms:

Technical details:
The text was updated successfully, but these errors were encountered: