tags:

views:

70

answers:

2

I want to send email with Arabic content through java mail , but every Arabic word in the message appears like ????????????? , how can i make the encoding to utf_8 in order to support Arabic language ??? since i use that code

    Message message = new MimeMessage(session);
    message.setFrom(new InternetAddress(from));
    message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to, false));
    message.setSubject(subject_a);
    message.setText(messageDetails_a);
    Transport.send(message);
+1  A: 

You have to create a MimeMessage (and keep it as a MimeMessage) and use the setSubject(subject, "UTF-8"); method for the subject.

setContent( messageContent, "text/html; charset=utf-8" ); will handle UTF-8 in the content.

With pure text :

setText(messageContent, "UTF-8");

Resources :

Colin Hebert
This will send a HTML-Email, but @Alaa wants to send a text message,
Michael Konietzka
Well, almost the same thing with `setText()`
Colin Hebert
That works properly , thanx
Alaa
+1  A: 

Just add some charset-information to the methods. If subject or message-body does contain other than US-ASCII characters, the default charset will be used for encoding. Explicitly setting the charset to UTF-8 will always be safe:

String charset="UTF-8";
message.setSubject(subject_a,charset);
message.setText(messageDetails_a,charset);
Michael Konietzka