I have a problem sending an Arabic text in email with java language.
this is my message in properties file:
mail.send=تجربة
I use this syntax in jave :
ResourceBundle dq_resource = ResourceBundle.getBundle("nls.myfile_ar");
String text= dq_resource.getString("mail.send")
but when I received email U have this text : اÙ?Ù?Ù?ضÙ?ع
I try also in java with this code :
String text= new String(dq_resource.getString("mail.send").getBytes(),Charset.forName("UTF-8"));
but I have this text in mail :
ا�?�?�?ض�?ع
You need to set a header for the mail, something like
message.setHeader("Content-Type", "text/plain; charset=UTF-8");
setHeader is a method of the Message class that allows you to set a header.
The easiest solution could be using strings normally ( without getBytes method ) changing the default encoding in your workspace for example eclipse.
Windows-->Preferences-->General-->workspace-->Text file encoding
Also you can try to convert UTF-8 to UTF-16 .
Related
I am about to use Paxful API method for sending a message to trade:
String message = "Do NOT PRESS 'Paid' button, until your transfer get 'Success' status.";
paxfulService.sendMessage(tradeId, message);
But here is what I see in the browser:
This is my fault, or Paxful API use unnecessary HTML encoding?
The API you are using is re-encoding the single quotes back into their hex values.
In your original message string try using ' in the place of the single quotes you have.
I am using the Java mail API to retrieve the emails from gmail via Imap and show it in the Webpage powered with AngularJS.
When I get the data for an email using javax.mail.Message.getContent() return as Object with charset - gb2312.
But my web page is using the UTF-8 charset, so while i am facing strange characters in the web page for some.
I need to convert from gb2312(or any) charset to the utf-8 to show correctly in the webpage.
Can anyone help with this ?
You can create a new String like this and convert it to UTF-8:
String s = new String(bytes, "OriginalCharset");
byte[] utfBytes = s.getBytes("UTF-8");
I think Java uses UTF-8 natively, but it's better to do it explicitly.
i want to get name and last name of application users by EditText view and send it to soap webservice to store in data base , i have problam when users enter data in arabic or persian it save data like this "?????" i try this code change encoding befor send data via webservice :
newLastName = new String(URLEncoder.encode(lastname.getText().toString(), "UTF-8"));
but when i check the encoding of string in server side with this code :
return mb_detect_encoding($lastName);
it`s return me ASCII !
how can i slove this problam ?
thanks
i send "سلام" to webservice and its return me "????" my problem is in php encoding system or in java encoding system ?
You should be able to use the URLDecoder.decode() function, like this:
String s = URLDecoder.decode(myString, "UTF-8");
more info string encoding easily
I'm using apache commons mail for sending e-mails with attachments.
My attachment file content is in hebrew and I can see it when I open the file , my problem is when the attachment file name is in hebrew I can't see the name I see ??? instead. (the content I still see o.k).
this is my code:
String attachment_file_name = "קובץ מס 1";
HtmlEmail email = new HtmlEmail();
email.setHostName(smtp_server);
email.addTo(to_email;
email.setFrom(from_email , "XXXXXXX");
email.setSubject(subject);
email.setCharset("UTF-8");
email.setHtmlMsg(body);
email.attach(new ByteArrayDataSource(attachment_file_.toByteArray(), "application/pdf"),
attachment_file_name ,
"attachment pdf",
EmailAttachment.ATTACHMENT);
email.send();
what do I need to do inorder to see the file name in hebrew (in the correct encoding) ?
Thank's In Advance.
I believe you have to encode it.
Javamail, the core library requires this
Set the System property "mail.mime.encodeparameters" to "true".
I want to send a URL request, but the parameter values in the URL can have french characters (eg. è). How do I convert from a Java String to Windows-1252 format (which supports the French characters)?
I am currently doing this:
String encodedURL = new String (unencodedUrl.getBytes("UTF-8"), "Windows-1252");
However, it makes:
param=Stationnement extèrieur into param=Stationnement extérieur .
How do I fix this? Any suggestions?
Edit for further clarification:
The user chooses values from a drop down. When the language is French, the values from the drop down sometimes include French characters, like 'è'. When I send this request to the server, it fails, saying it is unable to decipher the request. I have to figure out how to send the 'è' as a different format (preferably Windows-1252) that supports French characters. I have chosen to send as Windows-1252. The server will accept this format. I don't want to replace each character, because I could miss a special character, and then the server will throw an exception.
Use URLEncoder to encode parameter values as application/x-www-form-urlencoded data:
String param = "param="
+ URLEncoder.encode("Stationnement extr\u00e8ieur", "cp1252");
See here for an expanded explanation.
Try using
String encodedURL = new String (unencodedUrl.getBytes("UTF-8"), Charset.forName("Windows-1252"));
As per McDowell's suggestion, I tried encoding doing:
URLEncoder.encode("stringValueWithFrechCharacters", "cp1252") but it didn't work perfectly. I replayced "cp1252" with HTTP.ISO_8859_1 because I believe Android does not have the support for Windows-1252 yet. It does allow for ISO_8859_1, and after reading here, this supports MOST of the French characters, with the exception of 'Œ', 'œ', and 'Ÿ'.
So doing this made it work:
URLEncoder.encode(frenchString, HTTP.ISO_8859_1);
Works perfectly!