Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

how to get Arabic text in email subject with Java Mail

843834Jul 15 2009 — edited Jul 15 2009

I am using java mail api to send emails. It has to support for both English and Arabic Langauge. Its working fine with the body part for both the langauges Arabic and english.
But i am facing problems in Subject for Arabic langauge. Arabic Subject in emails works fine with gmail, yahoo and with some of the machines in outlook(where arabic support is installed/enabled), but in some of the machines the arabic subject displays as junk character or question marks (?????). below is the peace of code for reference.

I want that the arabic subject should work in the outlook in the machines even where arabic support is not installed. Kindly let me know where i am going wrong and advice me with the changes required to get the required out put.


----------------------------------------------------
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

private void sendMail() {
try {

Vector mainVector = new Vector();
Vector lowVector = new Vector();
ResultSet rs = executeQuery();
while (rs.next()) {
lowVector = new Vector();
lowVector.add(rs.getString(1));
lowVector.add(rs.getString(2));
{color:#ff0000}*lowVector.add(rs.getString(3));*{color}
lowVector.add(new String(rs.getString(4).getBytes("cp1256")));
lowVector.add(rs.getString(5));
mainVector.add(lowVector);
}
closeResultSet(rs);
for (int count=0;count<mainVector.size() ;count++ ) {
{color:#ff0000}*MimeMessage msg = null;*{color}
try {
lowVector = (Vector) mainVector.elementAt(count);
{color:#ff0000}*msg = new MimeMessage(session);*{color}

InternetAddress addressFrom = new InternetAddress(smtpEmailAddress);
Address[] replyTo = { new InternetAddress(replyEmailaddress)};
msg.setFrom(addressFrom);
InternetAddress addressTo = new InternetAddress((String) lowVector.elementAt(1));
msg.setRecipient(Message.RecipientType.TO,addressTo);
msg.setReplyTo(replyTo);
String dc = (String) lowVector.elementAt(4);
String mstr = (String) lowVector.elementAt(3);
{color:#ff0000}*String sub = (String) lowVector.elementAt(2);*{color}

strHtml = new StringBuffer();
strHtml.append("This is the mail body");


BodyPart bp = new MimeBodyPart();
bp.setContent(strHtml.toString(),"text/html");
Multipart multipart = new MimeMultipart("related");
multipart.addBodyPart(bp);

..............
...............
.................


msg.setContent(multipart);
{color:#ff0000}*msg.setSubject(sub, "UTF8");*{color}
Transport transport = session.getTransport("smtp");
transport.connect(EmailServer,smtpUser,smtpPassword);
msg.saveChanges();

Transport.send(msg);

transport.close();



catch (Exception e) {
e.printStackTrace();
}

}

}

------------------------------------------

Thanks & Regards,
Amjad Khan
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 12 2009
Added on Jul 15 2009
0 comments
956 views