7

I am using javax.mail to call a mail server and send a file as a mail attachment encoding the file name like this:MimeUtility.encodeText(filename,"UTF-8",null)

While this has been working fine on WildFly 8, it fails on WildFly 9.x with the same mail server. What I mean is that the attachment description is received in this format : =UTF-8BzrTOv866zrnOvM63IM68zrUgzrXOu867zrfOvc65zrrOsS5wZGY==

I have been trying to:

1) Find a relative setting on the application server - no luck.

2) Encode with ISO-8859-7 which only works occasionally since it seems to depend on the filename length and the presence of some characters.

3) Find a relative setting on the client (microsoft outlook) which i suppose misses some info to decode successfully.

Any ideas?

Thanks in advance!!

Sampada
  • 2,931
  • 7
  • 27
  • 39
evialxg
  • 71
  • 2
  • Hello. Have you managed to solve this issue? I'm am facing the exact same problem. Thank you. – Georgian May 27 '16 at 14:44
  • @GGrec The original question says "it fails on WildFly 9". What does this mean? To me it is not completely clear what and **where** goes wrong. It might be also useful to know what settings are used for the `file.encoding` system property and servlet encoding. – Daniel Szalay May 27 '16 at 18:37
  • Have you tried this - http://stackoverflow.com/a/31674972/5934435 ? – Sampada May 31 '16 at 11:55
  • Try using MimeUtility.encodeText(filename,"UTF-8","B") – Zaheer Baloch Jun 02 '16 at 16:50
  • @ZaheerBaloch That doesn't work either. I ended up stripping character accents, which is a temporary solution. – Georgian Jun 03 '16 at 14:15
  • @GGrec I think you don't need to manually `encodeText`, it should be handled by Java Mail API. – Tair Jun 03 '16 at 14:44

1 Answers1

0

To test your issue I created a demo project here. It sends a messages with non-ascii symbols in various parts, but doesn't use encodeText, as it is automatically handled by Mail API. I tested it with Wildfly 8, 9, 10 to send messages to http://mailtrap.io.

The first screen shows the message sent from Wildfly 8. The attachment is not sent properly, so it is absent:

Attachment is not properly sent in Wildfly 8

The second screen is a messages sent by Wildfly 9 (the same for 10). As you can see, there is an attachment with a proper filename:

For Wildfly 9 and 10 all right!

So what could be the issue here?

  • Wildfly 8 ships with Java Mail API 1.5.1
  • Wildfly 9 ships with Java Mail API 1.5.3
  • Wildfly 10 ships with Java Mail API 1.5.5

I think you are experiencing a bug in Java Mail version 1.5.1.

Most probably, you worked around that bug when coded against Wildfly 8 (manually using encodeText), now that workaround is causing you problems.

Tair
  • 3,779
  • 2
  • 20
  • 33
  • I removed the workaround. We are using WF 10. Apparently, on some machines it works fine, while on other it replaces special character with a question mark, or even the whole filename with "noname". Can there be a machine-dependent setting? – Georgian Jun 03 '16 at 15:18
  • @GGrec probably, you should specify default encoding for java: `bin/standalone.sh -Dfile.encoding=UTF-8` – Tair Jun 03 '16 at 16:03
  • @GGrec I'm sorry, the above comment is wrong :(, instead you should tweak `bin/standalone.conf`: `JAVA_OPTS=".... -Dfile.encoding=UTF-8"` – Tair Jun 03 '16 at 16:12
  • @GGrec what are your findings? Any difference after setting default encoding? – Tair Jun 06 '16 at 11:34
  • I ended up stripping accents as a second workaround. Will try your suggestion, though. – Georgian Jun 06 '16 at 12:03