Go Back   Velocity Reviews > Newsgroups > Java
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

Java - Wrong encoding in message subject

 
Thread Tools Search this Thread
Old 12-29-2005, 10:01 AM   #1
Default Wrong encoding in message subject


Hi everyone,

we wrote a simple cronjob for our server, which connects to a database,
gets some data eventually sends a mal via the java mail API.

Until now everything worked fine, but we since we updated our OS the
mail subject looks like:

=?ANSI_X3.4-1968?Q?Noch_freie_Plaetze_fuer:_=3FHSV-Hallencup_?=
=?ANSI_X3.4-1968?Q?2006=3F_am_8.1.2006_in_der?=

Uhm, I am really confused. The *really* strange thing is:

When I am executing the script via putty on the linux console, the
subject is being shown correctly - but running as cronjob the subject
is scrumbled

The following java code is used to create the message:

/*
* Created on 17.03.2005
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/


import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;

/**
* @author Mathias Deutz
*
*/
public class SendMail
{
public static void send(String recipient, String subject, String
message, String from)
{
try
{
Properties props = new Properties();
props.put("IP-ADDRESS", "IP-ADDRESS");

Session session = Session.getDefaultInstance( props );

Message msg = new MimeMessage( session );

InternetAddress addressFrom = new InternetAddress( from );
msg.setFrom( addressFrom );

InternetAddress addressTo = new InternetAddress( recipient );
msg.setRecipient( Message.RecipientType.TO, addressTo );

msg.setSubject( subject );
msg.setContent( message, "text/html" );
msg.saveChanges();

Transport.send( msg );
}
catch (Exception e)
{
e.printStackTrace();
}
}
}


And the following code sends the message:

SendMail.send("",betreff,nac hricht,"");

I hope I could make myself clear.

Thanks in advance!

Jan Lendholt



Jan-Hendrik Lendholt
  Reply With Quote
Old 12-29-2005, 10:28 AM   #2
Gordon Beaton
 
Posts: n/a
Default Re: Wrong encoding in message subject
On 29 Dec 2005 02:01:33 -0800, Jan-Hendrik Lendholt wrote:
> we wrote a simple cronjob for our server, which connects to a
> database, gets some data eventually sends a mal via the java mail
> API.
>
> Until now everything worked fine, but we since we updated our OS the
> mail subject looks like:
>
>=?ANSI_X3.4-1968?Q?Noch_freie_Plaetze_fuer:_=3FHSV-Hallencup_?=
>=?ANSI_X3.4-1968?Q?2006=3F_am_8.1.2006_in_der?=
>
> Uhm, I am really confused. The *really* strange thing is:
>
> When I am executing the script via putty on the linux console, the
> subject is being shown correctly - but running as cronjob the subject
> is scrumbled


Cron jobs typically do not run in a login shell, and therefore they
often have a different environment than you see from the login shell.
It's not unlikely that you fail to set the proper locale settings in
one of these, and that other one sees a system default.

If you want to specify a default locale, you should be able to do so
in your code as well. I have no experience with javax.mail, but have a
look at the documentation for javax.mail.internet.MimeUtility for some
clues.

/gordon

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e


Gordon Beaton
  Reply With Quote
Old 12-29-2005, 10:45 AM   #3
Igor Planinc
 
Posts: n/a
Default Re: Wrong encoding in message subject
Jan-Hendrik Lendholt wrote:
> Hi everyone,
>
> we wrote a simple cronjob for our server, which connects to a database,
> gets some data eventually sends a mal via the java mail API.
>
> Until now everything worked fine, but we since we updated our OS the
> mail subject looks like:
>
> =?ANSI_X3.4-1968?Q?Noch_freie_Plaetze_fuer:_=3FHSV-Hallencup_?=
> =?ANSI_X3.4-1968?Q?2006=3F_am_8.1.2006_in_der?=


MimeUtility.encodeText() is your friend. Just use it on the subject and you'll
be OK. In fact, use it on every header value.


Igor Planinc
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Sending a message into a newsgroup ninjaboy Software 0 10-26-2006 07:07 PM
How to create DVD-Audio disc Kryptoknight DVD Video 124 06-05-2004 07:14 PM
Turn $6 into $60000 GARANTEED!!! Zachary Keller DVD Video 2 10-08-2003 09:58 PM
Postal Lottery: Turn $6 into $60,000 in 90 days, GUARANTEED Louis DVD Video 0 09-30-2003 07:26 PM
Turn $6 into $60,000 in 90 days, GUARANTEED T.L.F. DVD Video 0 09-18-2003 07:14 AM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46