Skip to content
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

Handling special ASCII characters in FromName #78

Open
coel opened this issue Feb 13, 2023 · 3 comments
Open

Handling special ASCII characters in FromName #78

coel opened this issue Feb 13, 2023 · 3 comments

Comments

@coel
Copy link

coel commented Feb 13, 2023

I discovered if the FromName contains a comma the email was being rejected by our SMTP server. Doing more testing, I could see double quotes being stripped out and angle brackets also causing the email to be rejected.

Looking at RFC 5322 it seems like this display-name can be a quoted-string when it contains any of the specials.

In my case I escaped with a backslash any existing backslashes and double quotes, then wrapped the whole string in double quotes. It would be nice if the library handled this (though it would mean my code will cause extra characters to be sent 😅).

@domodwyer
Copy link
Owner

Hey @coel - thanks for the report!

Can you paste some example code / strings you're using? From reading I think you're saying you call:

mail.FromName("Hello, this is a test!")

Is that right? What about the quotes/angle brackets examples?

though it would mean my code will cause extra characters to be sent 😅

Lets co-ordinate any fix so you can avoid this happening 😂 🙏

@coel
Copy link
Author

coel commented Feb 13, 2023

Hi @domodwyer,

Thanks for looking into this and thanks for you work on this library.

Yes, that example is right. Seems like the behaviour from the SMTP server will vary. Trying against my personal Gmail I can see the emails are accepted and From just gets transplanted to X-Google-Original-From. However, against Amazon SES here are the results I get for different FromName values:

Preston, Bill S rejected with 554 code and message User name is missing: 'Preston'.

Ted "Theodore" Logan accepted, but the name in From is shown as Ted Theodore Logan.

Cake <3 rejected with 554 code and message Local address contains control or whitespace.

@domodwyer
Copy link
Owner

Thank you!

Looks like something that can definitely be improved! I don't have SES setup, so it'll take me a while to test this and work on a fix (I need a reproducer so I can inspect the headers each way for various inputs).

I'll add this to my TODO list, but if you fancy opening a PR I'll happily review that too!

Thanks again,

Dom

@domodwyer domodwyer reopened this Mar 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants