Problem with characters in mail

N

neoivan

I have a class that sends an email with javamail, with a text like
this one:

"Estimado Iván Escobedo:

En nacion.com queremos conocer más a nuestros lectores para ofrecerles
productos y servicios de mayor calidad. Por ello, a partir del 6 de
agosto, nacion.com le solicitará a todos nuestros visitantes que
completen un breve registro obligatorio."

The problem is that when the mail arrives to its destination, it
arrives this way:

"Estimado Iv?n Escobedo:

En nacion.com queremos conocer m?s a nuestros lectores para ofrecerles
productos y servicios de mayor calidad. Por ello, a partir del 6 de
agosto, nacion.com le solicitar? a todos nuestros visitantes que
completen un breve registro obligatorio."

All the á, é, í, ó, ú, etc special characters are replaced with "?".

What could be the problem and how to resolve it?

Thanks
 
R

Roedy Green

I have a class that sends an email with javamail, with a text like
this one:

The problem is with the encoding, either where you read the data and
convert it to unicode or where you package it up as the message body.

You have to pick an encoding that knows those Spanish characters.

You might use JavaMail to examine some working email to see what
encoding it uses.

Logically you should be able to use UTF-8, but I don't know how well
that is supported in email clients.

I had a quick look over the JavaMail classes. I saw various
getEncoding methods, but no setEncoding. Perhaps you are supposed to
encode manually and put a field in the header.
 
N

neoivan

Thanks for the replay.

Does anybody know how to encode to UTF-8 ?????
I would really appreciate an example code to do that.
 
V

Van Glass

Most of the email messages I have seen encode this using IS0-8859-1.
If the data is in one of the MIME headers it must encode it according
to RFC 2047 which BASE64 encodes the data as only US-ASCII characters
can appear in message headers.

I'm not sure about the JavaMail equivalent but you can do this using
the com.jscape.inet.email.EmailMessage#setBody(String body, String
characterSet) method where body is the body of the message and
characterSet is the character set used e.g. iso-8859-1

To do this in the message headers, for example the Subject use the
com.jscape.inet.email.EmailMessage#setSubject(String subject, String
characterSet)

All of these classes are found in iNet Factory at
http://www.jscape.com/inetfactory/index.html
 
N

Neomorph

Thanks for the replay.

Does anybody know how to encode to UTF-8 ?????
I would really appreciate an example code to do that.

The String class has some support for that.
You would convert a String to a byte [] array using
getBytes(String encoding).

Or you can use a OutputStreamWriter for that while you are sending - it
encodes automatically, and you can specify an ecoding method in its
constructor.

I haven't found a way yet to figure out which encoding formats are
supported by these, but in pure text e-mail Quoted-printable and Base 64
are the character encodings, and you can use MIME or UUEncode to attach
files.
For HTML e-mail you use MIME and set encoding as if for HTML pages.
Cheers.
 
N

Neomorph

Thanks for the replay.

Does anybody know how to encode to UTF-8 ?????
I would really appreciate an example code to do that.

The String class has some support for that.
You would convert a String to a byte [] array using
getBytes(String encoding).

Or you can use a OutputStreamWriter for that while you are sending - it
encodes automatically, and you can specify an ecoding method in its
constructor.

I haven't found a way yet to figure out which encoding formats are
supported by these, but in pure text e-mail Quoted-printable and Base 64
are the character encodings, and you can use MIME or UUEncode to attach
files.
For HTML e-mail you use MIME and set encoding as if for HTML pages.
Cheers.
 
J

Jon A. Cruz

Neomorph said:
I haven't found a way yet to figure out which encoding formats are
supported by these, but in pure text e-mail Quoted-printable and Base 64
are the character encodings, and you can use MIME or UUEncode to attach
files.


Actually, those are "content transfer encodings", not "character encodings"

"Character encodings" in mail would be:
ISO-8859-1
US-ASCII
UTF-8
etc.

"Content transfer encodings" tell how to get original bytes out of the
message. "Character encodings" then tell one how to interpret those
bytes as characters.
 
G

GaryM

(e-mail address removed) (neoivan) wrote in
BodyPart text = new MimeBodyPart();
text.setText(textmessage);
content.addBodyPart(text);

You can try doing this :

text.setContent(testmessage, "text/plain; charset=\"UTF-8\"";

However I have tried numerous ways to replicate this problem and
everytime my server and also Yahoo's server shows it correctly no mater
what I do.

Can you post the full headers of the message that is not working
including the bodypart boundary headers? I suspect it is not java mail
at all, but your server that cannot deal with it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top