Skip to content

Issue with attachments sent to certain email providers (targets) #231

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

Closed
staniko opened this issue Oct 18, 2019 · 5 comments
Closed

Issue with attachments sent to certain email providers (targets) #231

staniko opened this issue Oct 18, 2019 · 5 comments
Labels

Comments

@staniko
Copy link

staniko commented Oct 18, 2019

We discovered, that for certain email providers not all attachments are working, when they contain special characters or blanks e.g. "Köln Ausflugsziel.pdf". Gmail can handle this, but incamail.ch for example not.

We solved this by patching the MimeMessageHelper.java with following line (escaping the fileName and taking the filename variable also for the name attribute, because if non US-ASCII chars are used in attachment name, the attachment extension is changed to .dat. This happens maybe because Simple Java Mail always uses application/octet-stream as Content-Type of attachments instead of application/pdf or image/png, etc.

MimeMessageHelper.java:240:
attachmentPart.setHeader("Content-Type", contentType + "; filename=\"" + fileName + "\"; name=\"" + fileName + "\"");

Would be great if someone can crosscheck this and we add it to the main code. For us it works now with all kinds of attachments to various providers.

Best regards

Stan

@bbottema
Copy link
Owner

bbottema commented Oct 20, 2019

Interesting since that was recently changed to handle white spaces, which I think takes care of escaping the name as well. Which version are you on, because this was implemented in 5.4.0 (see #226).

I'm not sure using the filename for name is a good idea though. There is some logic to determine what the sender had meant to use, but for 6.0.0 in the develop branch a bug was fixed regarding determining the extension (#151).

I created a new branch off master for you with just that change from develop. Maybe you can try that patch in your branch and see if it fixes your problem.

because if non US-ASCII chars are used in attachment name, the attachment extension is changed to .dat

This is odd behavior, can you show me where this happens?

@staniko
Copy link
Author

staniko commented Oct 25, 2019

Thanks a lot, we check it within the next 3 weeks and respond then. Maybe the .dat issue is also resolved with the latest version.

@bbottema bbottema removed this from the 5.6.0 milestone Oct 27, 2019
@bbottema
Copy link
Owner

Any news?

@bbottema
Copy link
Owner

bbottema commented Dec 3, 2019

Closing this issue as invalid, as I can't proceed without more information. I'll keep the branch around for you for some more time.

I'll be happy to reopen once you can tell me more.

@pbernet
Copy link

pbernet commented Mar 26, 2020

Thanks for maintaining this convenient library.
I can confirm that upgrading to the latest version 6.0.3 fixed the issue. This works with all our email providers:

mailBuilder.withAttachment("Köln Ausflugsziel.pdf", new FileDataSource(myFile));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants