Skip to content

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

Closed

Description

@staniko

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

Activity

  1. added a commit that references this issue on Oct 20, 2019
  2. bbottema commented on Oct 20, 2019

    @bbottema
    Owner

    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?

  3. added this to the milestone on Oct 20, 2019
  4. staniko commented on Oct 25, 2019

    @staniko
    Author

    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.

  5. removed this from the milestone on Oct 27, 2019
  6. bbottema commented on Nov 27, 2019

    @bbottema
    Owner

    Any news?

  7. bbottema commented on Dec 3, 2019

    @bbottema
    Owner

    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.

  8. pbernet commented on Mar 26, 2020

    @pbernet

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions