1

my j2ee app works was developed in eclipse elios with tomcat 7 as application server. My workstation has windows 7. In a jsp i have an input text for sending mail to several user. In windows, the character like è works fine, i receive the mail and i see the è; when i deploy the war on tomcat on linux centOS, i don't see the è, but a strange character. this is the function that send email:

public boolean inviaMail() throws Exception{
        boolean invio=true;
        try {
            Properties props = System.getProperties();
            // Setup mail server
            props.put("mail.smtp.host", HOST);
            // Get session
            Session session = Session.getDefaultInstance(props, null);
            // Define message
            MimeMessage message = new MimeMessage(session);
            message.setHeader("Content-Type", "text/html; charset=UTF-8");
            message.setFrom(new InternetAddress(MITTENTE));
            message.addRecipient(Message.RecipientType.TO, new InternetAddress(userTo));

            message.setSubject(OGGETTO, "UTF-8");
            message.setText(testoMsg, "UTF-8");
            Transport.send(message);
        } catch (Exception e) {
            invio=false;
            System.out.println("errore.invio.mail:" + e.getMessage());
        }
        return invio;
    }

i think the problem is the tomcat configuration on linux, do you have some tips for me?

Konstantin Yovkov
  • 62,134
  • 8
  • 100
  • 147
  • Check what is encoding for your source files (File -> Properties -> Resource). Especially for files you have OGGETTO and *testoMsg* strings. – agad Dec 18 '14 at 15:14

2 Answers2

1

i have added accept-charset="UTF-8" in the form and a system.out.println in the class. This is what i see in the catalina.out: note that àè ì ò ù are the input of the form à è ì ò ù, while the text "Non rispondere a questa mail che � stata generata in automatico." is static and written in the source.

Avviso per gli utenti della sede: Fagnoni accentate: queste sconosciute à è ì ò ù


Non rispondere a questa mail che � stata generata in automatico. Per qualsiasi chiarimento contatta il referente dell'ordine oppure il tuo referente di sede

0

The first step to solve such bugs is to make sure that the input is correct. What's the encoding of the form? See this question for details: Setting the character encoding in form submit for Internet Explorer

If the form sends the data correctly, it gets mangled on the way. Set a breakpoint in the code and look at the variables. Do they look correct? If not, then you need to check the code which fills them. If they are correct, then you need to look at a dump of the mail message.

Community
  • 1
  • 1
Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820