Reputation: 11
I am currently working on a module which send mails to customers in multiple languages from a server.
I have stored the mail contents (to, subject and body) in a database and retrieving from it.
All the mail contents are stored in DB as unicode (eg: ضنتةى
to display arabic characters.)
I am using Apache's commons-email api to send mails. (version :commons-email-1.1.jar).
Coded in JAVA.
Mail sent using a Gmail SMTP host.
When the mail is sent and received by the customer-->The message body is translated and arabic characters are display.
Problem: The subject shows the unicode as it is in my DB. Translation does not take place.
I am aware that some mail header configuration has to be done, but not sure what and how. Also RFC 2047 seems to provide a solution, but how do I use this particular RFC?
Thanks in advance. -Chandan
Upvotes: 0
Views: 873
Reputation: 596582
Read RFCs 2045 - 2049 for the proper way to send Unicode data in email.
2045: Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies
2046: Multipurpose Internet Mail Extensions (MIME) Part Two: Media Types
2048: Multipurpose Internet Mail Extensions (MIME) Part Four: Registration Procedures
2049: Multipurpose Internet Mail Extensions (MIME) Part Five: Conformance Criteria and Examples
Upvotes: 0
Reputation: 115338
As @deceze said you do not "really" work with unicode. You are using the HTML notation to mark unicode characters. The body of your email is formatted as HTML, so email client interprets them just as browser does.
The email subject is not a part of HTML formatted body, so it is not shown correctly.
You should either switch to really working with unicode, i.e. define DB encoding as UTF-8 and store there unicode texts, so that you will not see texts like ضنتةى
but will see ضنتةى instead.
In this case everything will work. If you cannot do this for any reason you have to perform the "translation" in your java code.
BTW additionally to this translation you should specify the document direction rtl
- right to left. Otherwise the text will be adjusted to the left on systems with default left-to-right document direction.
Upvotes: 3