f



javax.mail sends mail with broken charset

Hello,

I send mail with javax.mail and I noticed that some special chars are 
broken.

I am using UTF-8 on my development system, where the mail generating 
code is produced. The received mail also contains "charset=UTF-8".

But it's broken. The string "��" is delivered as "=E4=DF" ( see below).

How can I fix this?

Laura


Message-ID: 
<13382290.1.1401258077688.JavaMail.tomcat7@h1403230.stratoserver.net>
Subject: Test
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Date: Wed, 28 May 2014 08:21:17 +0200 (CEST)

Test: =E4=DF

0
Laura
5/28/2014 6:30:18 AM
comp.lang.java.programmer 52711 articles. 1 followers. Post Follow

13 Replies
819 Views

Similar Articles

[PageSpeed] 7

2014-05-28 08:30, Laura Schmidt skrev:
> Hello,
> 
> I send mail with javax.mail and I noticed that some special chars are
> broken.
> 
> I am using UTF-8 on my development system, where the mail generating
> code is produced. The received mail also contains "charset=UTF-8".
> 
> But it's broken. The string "��" is delivered as "=E4=DF" ( see below).
> 
> How can I fix this?
> 
> Laura
> 
> 
> Message-ID:
> <13382290.1.1401258077688.JavaMail.tomcat7@h1403230.stratoserver.net>
> Subject: Test
> MIME-Version: 1.0
> Content-Type: text/plain; charset=UTF-8
> Content-Transfer-Encoding: quoted-printable
> Date: Wed, 28 May 2014 08:21:17 +0200 (CEST)
> 
> Test: =E4=DF
> 

Did you intend to send the two characters "��", i e LATIN SMALL LETTER A
WITH TILDE, and LATIN CAPITAL LETTER SHARP S? These are iso-8859-1
characters, correctly encoded as "=E4=DF" in quoted-printable. It seems
to be an interpretation error at the receiving end.

-- 
Lars Enderin
0
Lars
5/28/2014 9:13:18 AM
2014-05-28 11:13, Lars Enderin skrev:
> 2014-05-28 08:30, Laura Schmidt skrev:
>> Hello,
>>
>> I send mail with javax.mail and I noticed that some special chars are
>> broken.
>>
>> I am using UTF-8 on my development system, where the mail generating
>> code is produced. The received mail also contains "charset=UTF-8".
>>
>> But it's broken. The string "��" is delivered as "=E4=DF" ( see below).
>>
>> How can I fix this?
>>
>> Laura
>>
>>
>> Message-ID:
>> <13382290.1.1401258077688.JavaMail.tomcat7@h1403230.stratoserver.net>
>> Subject: Test
>> MIME-Version: 1.0
>> Content-Type: text/plain; charset=UTF-8
>> Content-Transfer-Encoding: quoted-printable
>> Date: Wed, 28 May 2014 08:21:17 +0200 (CEST)
>>
>> Test: =E4=DF
>>
> 
> Did you intend to send the two characters "��", i e LATIN SMALL LETTER A
> WITH TILDE, and LATIN CAPITAL LETTER SHARP S? These are iso-8859-1
> characters, correctly encoded as "=E4=DF" in quoted-printable. It seems
> to be an interpretation error at the receiving end.
> 
Or you have actually sent the two characters as iso-8859-1, despite the
header. Could you change to 8-bit instead of quoted-printable?

-- 
Lars Enderin
0
Lars
5/28/2014 9:24:05 AM
On 5/28/2014 1:30 AM, Laura Schmidt wrote:
> Hello,
>
> I send mail with javax.mail and I noticed that some special chars are
> broken.
>
> I am using UTF-8 on my development system, where the mail generating
> code is produced. The received mail also contains "charset=UTF-8".
>
> But it's broken. The string "äß" is delivered as "=E4=DF" ( see below).

It's not broken. Well, it's as functional as the mail specifications 
are, which isn't terribly great, but that's beside the point.

> Content-Transfer-Encoding: quoted-printable

See this line? It means that non-ASCII characters (and NUL and "bare" 
CR/LF as well, etc.) are "quoted" using an =XX, where X are hexadecimal 
characters. See section 6.7 of RFC 2045 for more details.

If what you expected was an 8-bit body that you could just slurp and 
understand without needing to do any complicated processing, then you 
are sadly extremely mistaken about how messed up the email 
specifications are. Email cannot be reliably processed via hacked up 
scripts reading/writing it manually; you need to use real libraries. 
I've been doing a running series on my blog on just how insane of a mess 
everything is.

[If you want an example, look at the source of this message to figure 
out how the emoji in my From: header is encoded. And then observe all 
the prior occurrences of people quoting that header and managing to 
mangle it. I find it quite amusing, personally.]

-- 
Beware of bugs in the above code; I have only proved it correct, not 
tried it. -- Donald E. Knuth
0
UTF
5/28/2014 2:01:23 PM
Thanks to Lars & Joshua,

the following change to my code solved the problem:

	msg.setContent (message,"text/plain;charset=utf-8");

Laura
0
Laura
5/29/2014 1:01:01 AM
On 05/29/2014 09:19 AM, Laura Schmidt wrote:

> the following change to my code solved the problem:

.... but I don't know why. The new mail reads like this:

Message-ID: 
<22731732.1.1401347792347.JavaMail.tomcat7@h1403230.stratoserver.net>
Subject: Test
MIME-Version: 1.0
Content-Type: text/plain;charset=utf-8
Content-Transfer-Encoding: quoted-printable
Date: Thu, 29 May 2014 09:16:32 +0200 (CEST)

Test: =C3=A4=C3=9F

The header is the same, but the code for "��" changed from "=E4=DF " to 
"=C3=A4=C3=9F".

Laura
0
Laura
5/29/2014 1:01:01 AM
Laura Schmidt <ls@mailinator.com> wrote:
> I send mail with javax.mail and I noticed that some special chars are 
> broken.
> I am using UTF-8 on my development system, where the mail generating 
> code is produced. The received mail also contains "charset=UTF-8".
> But it's broken. The string "äß" is delivered as "=E4=DF" ( see below).

Maybe you could post the crucial lines of your Java code, like the
one where you (maybe) explicitly set the charset (if this isn't just
the default on your machine), and those, where you pass that String 
or bytearray containing the two letters to some javax.mail... method.

> MIME-Version: 1.0
> Content-Type: text/plain; charset=UTF-8
> Content-Transfer-Encoding: quoted-printable
>
> Test: =E4=DF

Yes, this mail is definitely inconsistent/wrong.

PS: (for Lars) the first of the letters is an umlaut-a, and =E4 is the
  umlaut-a's quoted iso-8859-1 (or -15) representation, just not the
  expected quoted utf-8 one.

0
Andreas
5/29/2014 9:43:54 AM
Laura Schmidt <ls@mailinator.com> wrote:
> On 05/29/2014 09:19 AM, Laura Schmidt wrote:
>> the following change to my code solved the problem:
> ... but I don't know why. The new mail reads like this:
> Message-ID: <22731732.1.1401347792347.JavaMail.tomcat7@h1403230.stratoserver.net>
> Subject: Test
> MIME-Version: 1.0
> Content-Type: text/plain;charset=utf-8
> Content-Transfer-Encoding: quoted-printable
> Date: Thu, 29 May 2014 09:16:32 +0200 (CEST)
>
> Test: =C3=A4=C3=9F
>
> The header is the same, but the code for "äß" changed from "=E4=DF " to 
> "=C3=A4=C3=9F".

Now it is indeed correct.

=C3=A4 is quoted-printable(utf8(ä)) and =C3=9F is quoted-printable(utf8(ß))

PS: I started typing my other followup yesterday, but only today I noticed
that I hadn't sent it off, and did so, before checking what else had been
posted meanwhile...
0
Andreas
5/29/2014 9:48:36 AM
2014-05-29 09:35, Laura Schmidt skrev:
> On 05/29/2014 09:19 AM, Laura Schmidt wrote:
> 
>> the following change to my code solved the problem:
> 
> .... but I don't know why. The new mail reads like this:
> 
> Message-ID:
> <22731732.1.1401347792347.JavaMail.tomcat7@h1403230.stratoserver.net>
> Subject: Test
> MIME-Version: 1.0
> Content-Type: text/plain;charset=utf-8
> Content-Transfer-Encoding: quoted-printable
> Date: Thu, 29 May 2014 09:16:32 +0200 (CEST)
> 
> Test: =C3=A4=C3=9F
> 
> The header is the same, but the code for "��" changed from "=E4=DF " to
> "=C3=A4=C3=9F".
> 

That looks right. To see the original characters, you need a mail client
or other program that understands quoted-printable. In your first
attempt, you seem to have used ISO-8859-1 as the default encoding. What
default encoding does the JVM assume? Inside Java, the characters are
encoded as 16-bit characters, a form of UTF-16. The encoding only
matters when you write to or from a byte stream or file.

-- 
Lars Enderin
0
Lars
5/29/2014 9:56:39 AM
On Wed, 28 May 2014 11:13:18 +0200, Lars Enderin wrote:

> Did you intend to send the two characters "��", i e LATIN SMALL LETTER A
> WITH TILDE, and LATIN CAPITAL LETTER SHARP S? These are iso-8859-1
> characters, correctly encoded as "=E4=DF" in quoted-printable.

Andreas' Post reminded me that I meant to correct this the other day but
forgot - both of these are wrong: it's not LATIN SMALL LETTER A WITH TILDE
(that would have been =E3), it's LATIN SMALL LETTER A WITH DIAERESIS, and
instead of LATIN CAPITAL LETTER SHARP S (which would have been 1E9E) it is
LATIN SMALL LETTER SHARP S. Both of those show up as what they actually are
in your post.

Liebe Gruesse,
		Joerg

-- 
Ich lese meine Emails nicht, replies to Email bleiben also leider
ungelesen.
0
Joerg
5/29/2014 10:55:32 AM
On Wed, 28 May 2014 08:30:18 +0200, Laura Schmidt <ls@mailinator.com>
wrote, quoted or indirectly quoted someone who said :

With a problem like this it a good idea to have a peek at the hex
messages going out with WireShark to help you decide if the fault lies
with sender or receiver.
-- 
Roedy Green Canadian Mind Products http://mindprod.com
Young man, in mathematics you don't understand things.
You just get used to them. 
~ John von Neumann (born: 1903-12-28 died: 1957-02-08 at age: 53)
0
Roedy
5/29/2014 10:31:31 PM
On 05/29/2014 09:35 AM, Laura Schmidt wrote:

> The header is the same, but the code for "��" changed from "=E4=DF " to
> "=C3=A4=C3=9F".

I forgot to say that the second mail is displayed correctly in the mail 
client (thunderbird) while the first one displays the code itself.

Laura
0
Laura
5/30/2014 1:01:01 AM
2014-05-30 12:16, Laura Schmidt skrev:
> On 05/29/2014 09:35 AM, Laura Schmidt wrote:
> 
>> The header is the same, but the code for "��" changed from "=E4=DF " to
>> "=C3=A4=C3=9F".
> 
> I forgot to say that the second mail is displayed correctly in the mail
> client (thunderbird) while the first one displays the code itself.

Because the two bytes encoded as =E4=D7 are not valid UTF-8, of course.
Look up UTF-8 in Wikipedia, for example.

-- 
Lars Enderin
0
Lars
5/30/2014 11:22:04 AM
2014-05-30 13:22, Lars Enderin skrev:

> Because the two bytes encoded as =E4=D7 are not valid UTF-8, of course.
> Look up UTF-8 in Wikipedia, for example.
> 
DF, not D7

-- 
Lars Enderin
0
Lars
5/30/2014 6:01:11 PM
Reply:

Similar Artilces:

pls help me when i sent mail, it vil sending twice instead of once ,am using java.mail,am sending my code....
Every thing is working fine but it sending message twice instead of once. in the Forget.jsp page am accepting username or email <struts-config.xml> <form-beans> <form-bean name="forgotUname" type="org.apache.struts.validator.DynaValidatorForm"> <form-property name="userName" type="java.lang.String" /> <form-property name="email" type="java.lang.String" /> </form-bean> </form-beans> <action-mappings> <action path="/Forgot" name="forgotUname" type=&q...

Mail will not send mail but will receive mail
At work I have a Wallstreet with Jaguar connected to a DSL line. Up until a couple days ago I have been able to use my personal ISP smtp address to send and receive mail. This is not the same company as the DSL provider. A couple days ago I was able to receive posts but not send them. I tried repairing permissions, and trashing the Mail prefs. Finally I emailed my ISP and the response was that I have to use the DSL carrier's smtp address. Yet, I've been using my personal ISP's smtp address for about a year. At home I use a dialup with the ISP and everything works fi...

sending mail otherthan mail()
Hello everyone, My server admin has blocked the mail() due to some spam problems. I need to send emails using php. Can anyone guide me to the best method of sending emails using php without using mail(). If there is any tweak to be done at the server level I will be able to convince the admin. The server has linux Enterprice edition 3 with php 4.3.11 and cpanel/whm. Please guide me to the method and i will be able to collect other information about it from google. Thanks Jaunty Edward smilesinblues@gmail.com wrote: > My server admin has blocked the mail() due to some spam problems. I ...

Sending mail through Mail::Outlook
Hi, I am using Mail::Outlook to send email through Outlook. I've set out the code below. Everything works fine but I have two items on my wish list. 1. To be able to send attachments. I have tried '$message->Attachments('c:\file.txt');' and '$message->Attachments.Add('c:\file.txt');' but neither work. 2. To be able to send the email in html format but '$message->HTMLBody($body);' doesn't work. Are either of these possible using Mail::Outlook or do I need to go back to scratch and use another module? Thanks Paddy ###################...

CLASSPATH problem java.lang.NoClassDefFoundError javax/mail/MessagingException
Hi on AIX 4.3.3 with JDK1.3.1, my library is not found ?? Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/MessagingException My library location <e30>root$ pwd /test/v1/infosrv/classes/pdf5b <e30>root$ ls *.jar acrobat.jar itext-1.26.jar mailapi.jar pdf5b.jar smtp.jar activation.jar jdom.jar parser.jar pja.jar My Script $JAVA_HOME/jre/bin/java -Xbootclasspath/a:$r/$pja: \ -Dawt.toolkit=com.eteks.awt.PJAToolkit \ -Djava.awt.graphicsenv=com.eteks.java2d.PJAGraphicsEnvir onment \ ...

Send mail script step
I have a file CLASSES with the classes of a school and a file STUDENTS with the students of the shool. The two files are related with the Class_ID field. I have a layout with the data from one record of the CLASS file and a portal showing all the students in that class. I want to use a script to sent e-mails to all the students in that class (assuming that there is a e-mail address field in students file). If I use the "Use all Recordn in found set" flag the mail is sent to all the studends of the school and not only to the students of that class. If I use "Use the current rec...

Mail and imported mail in mail app
I imported my email from an iMac g5 to a MacBook Pro running Leopard. I now have an inbox, sent box, Trash, and underneath that a set of folders I'd created in Mail on the iMac for various mail stuff. Under that is a gmail heading (all my mail comes to Mail app from Gmail), and under that another inbox, sent box. Is there a way to meld these two inboxes? Last time I looked, a new mail coming in showed up in both places, requiring me to select each in turn. Ed In article <C73B46C2.2656D%kearnser@gmail.com>, Ed Kearns <kearnser@gmail.com> wrote: > I imp...

php mail() not sending to mail Clients (ie, Outlook, Apple Mail, thunderbird, etc..)
I have a send mail script on my site that. The emails are recieved by gmail, and yahoo, but not to mail clients like Outlook, Mail, etc...) Is this a problem with the script, or is it something I must change in php ini file? Thanks in advance for any help. here is the code. (im using it in conjunction with javascript for some AJAX stuff) if(!isset($_GET['action'])) { die("You must not access this page directly!"); //Just to stop people from visiting contact.php normally } /* Now lets trim up the input before sending it */ $name = trim($_GET['name']); //The sen...

java.lang.NoClassDefFoundError: javax/mail/Session Eclipse 3.0.2
I'm running an app under Eclipse 3.0.2 and getting the following runtime error: java.lang.NoClassDefFoundError: javax/mail/Session with the following line of code: session = Session.getDefaultInstance(props, null); The app compiles without a problem. The apps' classpath follows: <?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="src" path=""/> <classpathentry exported="true" kind="lib" path="/src/bin"/> <classpathentry exported="true" kind="con&quo...

How do I delete mail from mail file /var/mail/su after reading mails
I used to receive data in mail from users. I used to read those data and load that into a ORACLE table. However I am not able to delete those mails after reading and loading it. Currently I delete them manually when the mail file grow very big Is there a way we can delete these mails after we read it using shell script ? ...

Problem with Mail,mail won�t send
My partner has a G4 with OS X 10.3.9. Recently lots of messages have refused to send from her Mail Outbox,resulting in the App beachballing/having to be ForceQuit. Sometimes she gets the following error message:- �This message could not be delivered and will remain in your Outbox until it can be delivered. Verify that you have addressed the msg correctly.Check smtp settings in Mail preferences and verify any advanced setup with your system administrator�. I�ve tried the following things:- Repair permissions Zap PRAM Rebuild Mailboxes Tried trashing Mail prefs but when she tries to log in agai...

Pegasus Mail freezes when sending mail
Hello, We have Pegasus Mail version 4.41 set up on a Windows Network. The programs are run in workstation mode so that they are running the executables off the network. We are using a roaming profile. We have one particular computer that intermittently freezes up when sending mail. This workstation is a Windows XP Professional SP2 machine. The program becomes unresponsive (eternal hourglass), and even manually ending the program from task manager won't work. The person using this workstation tells me it seems to happen more when replying to messsages from a user than when ...

Why I can not send mail to this mail loop?
hasn't been delivered to the members, including myself. Why I can not send out mail? ...

Sending mail with mail() without header
Hi, I'm working on a website where there is a from from which I want to send the data by e-mail. When I send myself the result with mail($my_email, $title, $message) everything works fine and I receive a plain text email. However, the people for which I'm doing the site receive some kind of error when I do the same thing but delivered to them > mail($their_email, $title, $message) The error looks something like this: Your message cannot be delivered to the following recipients: Recipient address: services@theirdomain.com Reason: Illegal host/domain name found I also used s...

Web resources about - javax.mail sends mail with broken charset - comp.lang.java.programmer

Search · charset "UTF8" · GitHub
Build software better, together.

[HTML] <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Exercici - Pastebin.com
PASTEBIN - #1 paste tool since 2002 create new paste tools api archive faq PASTEBIN create new paste trending pastes sign up login my alerts ...

Talk:History of online games - Wikipedia, the free encyclopedia
This article is within the scope of WikiProject Video games , a collaborative effort to improve the coverage of video games on Wikipedia. If ...

Hypertext Transfer Protocol - Wikipedia, the free encyclopedia
HTTP is the foundation of data communication for the World Wide Web . Hypertext is a multi-linear set of objects, building a network by using ...

Ancient City of Byllis - Fier, Albania - Home
Ancient City of Byllis, Illyria, Albania, Fier, Balkan, Europe charset=iso-8859-1" /> Home Historia e Bylisit Hulumtime Galeria Rregullorja e ...

Gemtree Caravan Park and Gem Stone Fossicking - Home
Gemtree is located 140kms North-East of Alice Springs, with bitumen road to the front gate! Nestled neatly amongst the native bush of the Plenty ...

Department of Local Government and Planning Department of Local Government and Planning
The Department of Local Government and Planning works closely with local governments and leads a coordinated Queensland Government approach to ...

BBM Canada
... broadcast measurement and consumer behaviour data, as well as industry-leading intelligence to broadcasters, advertisers and agencies. charset=iso-8859-1" ...

Apple: iTunes Match to Launch in Canada Shortly After US Debut
Our previous post referred to Tim Cook answering emails from customers just like Steve Jobs used to do. iPhoneinCanada.ca reader Sheldon did ...

2-Plants: US politicans attack BIO's GMO moratorium
... Subject : From : GENET Date: Tue, 29 Oct 2002 14:10:35 +0200 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii" Reply-To: ...

Resources last updated: 1/26/2016 9:37:19 PM