I retrieve a value from a DB field which looks like two boxes [][] in the sql/developer.
When I copy and paste that value to outlook (new message window) and send it to myself I can see the correct Chinese characters in the email 测试.
However If I do that via java code, meaning retrieve the value from db and send the email from java I get two ?? question marks in the resulting email in outlook.
The original setting in java code was:
Content-Type: text/plain;
I also tried to send the email with these settings:
Content-Type: text/plain; charset=UTF-8
Content-Type: text/html; charset=UTF-8
Nothing helped. Any ideas?
You also need to set your connection encoding to be utf-8
jdbc:mysql://localhost/some_db?characterEncoding=UTF-8
Try changing it in your control panel
Control Panel -> Regional and Language Options
Related
We need to send a multipart/form-data request containing two files. Since we had some issues with the requests, we set up a request bin page to try and analyze the requests themselves, since Postman seemed to work fine.
My second file is generated by a different service as a byte stream and represents a JSON object. This byte stream seems to have a NUL (0) byte terminator at the end.
If I add this second file to the multipart/form-data request, something like the following results:
With the body looking as follows:
--9ac41cec-a0ff-4afd-b687-6b8c2f1bddd6.
Content-Disposition: form-data; name="metadata"; filename="metadata-1584981615.json".
Content-Type: application/json.
Content-Length: 581.
.
{"...":"..."}.
--9ac41cec-a0ff-4afd-b687-6b8c2f1bddd6.
Content-Disposition: form-data; name="file"; filename="file-1584981615.json".
Content-Type: application/json.
Content-Length: 12205.
.
{"...":"..."}..
--9ac41cec-a0ff-4afd-b687-6b8c2f1bddd6--.
Obviously, this is supremely invalid. It seems that the multipart request is adding the . characters at the end of every line.
I was able to reproduce this behaviour with Spring Web 5.1.5.RELEASE, okHttp 3.14.7 and Apache HttpComponents 4.5.7. The behaviour does not seem to change if I remove the NUL (0) byte terminator from the byte stream.
Here's the odd part: the receiving webserver accepts this request as a valid multipart/form-data request.
For the record, here's what a valid request (that is also accepted by the webserver) looks like from request bin's point of view (different file):
--83611e7f-ad57-4893-9d1b-5ba2c4543d2a
Content-Disposition: form-data; name="metadata"; filename="metadata-1584982345.json"
Content-Type: application/json
Content-Length: 895
{"...": "..."}
--83611e7f-ad57-4893-9d1b-5ba2c4543d2a
Content-Disposition: form-data; name="file"; filename="file-1584982345.json"
Content-Type: application/json
Content-Length: 9868
{"...": "..."}
--83611e7f-ad57-4893-9d1b-5ba2c4543d2a--
Aside from having the explicit terminator at the end (which does not seem to make a difference at all), the byte stream does not look broken. new String(bytes) gives a valid JSON object. So I'm thinking it has to be something else.
Has anyone encountered this issue before? I'm unsure how to proceed with debugging this issue, and I'm fairly certain that sending improper requests, even though they might be accepted by the remote server at this time, almost certainly guarantees that my code will break somewhere along the line...
I am trying to figure out how to manage an attachment of a mail that has the filename chunked. I am on java 1.6 with javamail 1.5.1 and my code can manage all kind of mails but when I receive one from a specific adress(i can't talk with those guys) it doesn't import some attachments properly. When I open those atachments(assuming that this one's name is filename without extension.extension) with notepad I find this:
Content-Type: application/octet-stream;
name*0="filename without extension"; name*1=.extension
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename*0="filename without extension"; filename*1=.extension
before the base64 content. I tried to search for similar problems but I have the exact filename but it's splitted and the BodyPart.getFilename() method returns null. I was thinking about taking the whole header and work on that.
This should be supported by your version of Javamail.
System.setProperty("mail.mime.decodeparameters", "true");
For more info, search for "RFC 2231" on the package documentation of javax.mail.internet:
https://docs.oracle.com/javaee/6/api/javax/mail/internet/package-summary.html
With Spring 3.0.5, I can generate emails by calling VelocityEngineUtils.mergeTemplateIntoString(VelocityEngine velocityEngine, String templateLocation, Map model). This method generates a string that is fully compliant with MIME mail.
With Spring 3.2.11, that method is unsupported: one must use VelocityEngineUtils.mergeTemplate(VelocityEngine velocityEngine, String templateLocation, String encoding, Map model, Writer writer) with an additional encoding parameter.
Being a mailing context, I tried org.apache.commons.codec.CharEncoding.US_ASCII (which equals to US-ASCII) but it totally break my mails. All clients I tried (Outlook web mail, Outlook 2013, Windows 8's Mail) don't see subject and display all the MIME parts like the following:
------=_Part_0_1846461141.1413184892265
Content-Type: multipart/related; boundary="----=_Part_1_249771572.1413184892276"
------=_Part_1_249771572.1413184892276
Content-Type: multipart/alternative; boundary="----=_Part_2_861087694.1413184892311"
------=_Part_2_861087694.1413184892311
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
(Look at UTF-8!)
The question is: what is the correct way to invoke mergeTemplateIntoString with encoding argument?
i've a plugin that should process some mails, so i need to get attachments from an imap mail and do some stuff.
All seem to work but i've a single mail that have a strange attachment header and i'm not able to get it correctly, here the attachment header:
--_01d0aeb2-3f01-4153-9121-66b7af6924f1_
Content-Type: application/msword
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=
"=?iso-8859-1?Q?Atto_Aziendale_(xxx=E0_del_xxx_xxx_-_xxx)=2C_Pr?=
=?iso-8859-1?Q?of.xxx_xxx_-_Dr.xxx_xxx.doc?="
"x" are for privacy but that should not be important, the problem is that when i try to get the filename of this attachment with javaMail:
Attachment att = new Attachment(mailPart);
String filename = att.getFilename();
i get only this: "Atto Aziendale (xxx del xxx xxx - xxx), Pr"
seem that it doesn't read the second line.
I've also tried to get the filename in another way:
mailPart.getHeader("Content-Disposition").getAttribute("filename").toString();
and that return: filename="=?iso-8859-1?Q?Atto_Aziendale_(xxx=E0_del_xxx_xxx_-_xxx)=2C_Pr?==?iso-8859-1?Q?of.xxx_xxx_-_Dr.xxx_xxx.doc?="
so it seem that the attribute is correctly readed, but if i try to get:
mailPart.getHeader("Content-Disposition").getAttribute("filename").getValue();
then i get again a truncated filename: "Atto Aziendale (xxx del xxx xxx - xxx), Pr"
anyone know how to get the complete filename or how i should decode the filename attribute?
thanks for any help
If you're using IMAP, the IMAP server is parsing the mail headers and returning the parsed values to the JavaMail client. Your Content-Disposition header has several continuation lines. The IMAP server needs to properly combine those continuation lines and return the parameter values. It looks like the server is omitting the whitespace implied by the continuation line and joining the "?=" with the "=?". Without whitespace between them, they appear to be one encoded word instead of two, which likely explains why you're getting the wrong results when decoding them.
Try setting the System property "mail.mime.decodetext.strict" to "false"; this may allow JavaMail to decode the value. See the javadocs for the javax.mail.internet package for details.
Whenever I try to know the content type of multipart message by using javamail API, I'm getting the content type as:
multipart/mixed;
boundary="----=_Part_19_32879825.1271840022140"
I've already disable my antivirus, but I'm still not able to terminate that boundary.
I'm trying to send the message using IMAP protocol.
I'm using Hmail Server.
Could anyone please tell me the reason of it?
If the email that you're sending contains an attachment, this is not an error. It is how the message header is really supposed to be:
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="frontier"
This is a message with multiple parts
in MIME format.
--frontier
Content-Type: text/plain
This is the body of the message.
--frontier
Content-Type: application/octet-stream
Content-Transfer-Encoding: base64
PGh0bWw+CiAgPGhlYWQ+CiAgPC9oZWFkPgogIDxib2R5PgogICAgPHA+VGhpcyBpcyB0aGUg
Ym9keSBvZiB0aGUgbWVzc2FnZS48L3A+CiAgPC9ib2R5Pgo8L2h0bWw+Cg==
--frontier--
From: http://en.wikipedia.org/wiki/MIME
The value of the boundary attribute indicates where each message part finishes and the next one begins.
EDIT:
If you're getting an error related to missing end boundary (is that your question?), then you may want to set the missing end boundary to false:
The
mail.mime.multipart.ignoremissingendboundary
property may be set to false to cause
a MessagingException to be thrown if
the multipart data does not end with
the required end boundary line. If
this property is set to true or not
set, missing end boundaries are not
considered an error and the final body
part ends at the end of the data
That's from the JavaMail API.