Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2005

Tip: Looking for answers? Try searching our database.

Wrong encoding in message subject

Thread view: 
Jan-Hendrik Lendholt - 29 Dec 2005 10:01 GMT
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("j.lendholt@sbxmgmt.com",betreff,nachricht,"info@sbxmgmt.com");

I hope I could make myself clear.

Thanks in advance!

Jan Lendholt
Gordon Beaton - 29 Dec 2005 10:28 GMT
> we wrote a simple cronjob for our server, which connects to a
> database, gets some data eventually sends a mal via the java mail
[quoted text clipped - 11 lines]
> 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

Signature

[  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

Igor Planinc - 29 Dec 2005 10:45 GMT
> Hi everyone,
>
[quoted text clipped - 6 lines]
> =?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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.