Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Send UTF-8 Email "apache commons"

Posted on 2011-09-29
8
Medium Priority
?
364 Views
Last Modified: 2012-05-12
Dear Experts,

I have this method that send an email that has arabic text html email using apache.
The email is not encoded properly

please this is urgent , it is in production ><

Thaaaaanks



public boolean sendEmail(Action email,Form form,Vector formData) throws SendFailedException,
	 MessagingException,javax.mail.internet.AddressException,Exception{


 
 boolean status=false;
 String subject = formatEmail(email.getParam1(),form,formData);
 String emailTemplate = formatEmail(email.getParam2(),form,formData);
 String from = formatEmail(email.getParam3(),form,formData);
 String to = formatEmail(email.getParam4(),form,formData);
 
  Config conf = new Config("uaeu_server_config.prop");
  String host= conf.get("mail_server"); //"195.229.162.3";
  int port =Integer.parseInt(conf.get("mail_port"));
  String[] recipients = to.split(",");
  InternetAddress[] addressTo = new javax.mail.internet.InternetAddress[recipients.length];
  for (int i = 0; i < recipients.length; i++){
	  System.out.println();
    addressTo[i] = new javax.mail.internet.InternetAddress(recipients[i]);}
  Collection toCollection = Arrays.asList(addressTo); 
  HtmlEmail htmlEmail = new HtmlEmail();
  htmlEmail.setHostName(host);
  htmlEmail.setTo(toCollection);
  htmlEmail.setFrom(from);
  htmlEmail.setSubject(subject);
  htmlEmail.setHtmlMsg((new StringBuilder()).append("<html><head><META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=UTF-8" + "\"></head><body>").append(emailTemplate).append("</body></html>").toString());
  //set the alternative message
 htmlEmail.setTextMsg("Your email client does not support HTML messages");
 //send the email
 htmlEmail.send();




return true;
 
 }

Open in new window

0
Comment
Question by:Web_Admin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 36814460
>>The email is not encoded properly

In what way?
0
 

Author Comment

by:Web_Admin
ID: 36816705
see below text i copied from the email -.-
House Transfer Request
Personal Information 	المعلومات الشخصية
Banner ID : 	$BANNERID$ 	رقم الملف (البانر ) :
Requester Name: 	$REQUESTERNAME$ 	اسم مقدم الطلب :
College/Dept.: 	$DIVISIONNAME$& - $DEPARTMENTNAME$ 	كلية / إدارة :
Position: 	$POSITION$ 	الوظيفة :
Marital Status: 	$MARITALSTATUS$ 	الحالة الاجتماعيØ

Open in new window

0
 
LVL 86

Accepted Solution

by:
CEHJ earned 2000 total points
ID: 36817809
Could you please (preferably in your code temporarily) write 'emailTemplate' to a file and attach it to this post. Try not to touch it otherwise after doing so. Something like
Writer out = new OutputStreamWriter(new FileOutputStream("ee.txt"), "UTF-8");
out.write(emailTemplate);
out.close();

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 86

Expert Comment

by:CEHJ
ID: 36817823
btw, it looks like your template is still in template form somewhat (as opposed to having had its placeholders filled out)
0
 

Author Comment

by:Web_Admin
ID: 36817976
@CEHJ : I will try to write the template string to file , btw i printed the template string in the jsp before pass it to metod , in jsp it displays perfectly
0
 

Author Comment

by:Web_Admin
ID: 36898503
CEHJ: Yes I was testing and send the template as it is and it has arabic content too
0
 

Author Comment

by:Web_Admin
ID: 36898515
Thanks , it works now and I don't know the reason o.O
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 36899087
:)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video teaches viewers about errors in exception handling.
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question