0

I've got the following webservice method, which is called by REST:

public boolean sendMail(String text) {
    Email email = new SimpleEmail();
    email.setHostName(MAIL_SERVER);
    email.setSmtpPort(25);
    email.setAuthenticator(new DefaultAuthenticator(MAIL_USER, MAIL_PASSWORD));
    try {
        email.setFrom(MAIL_SENDER);
        email.setSubject(text);
        email.setMsg(text);
        email.addTo(MAIL_RECEIVER);
        email.send();
        return true;
    } catch (EmailException e) {
        return false;
    }
}

The request is like sendMail?text=aäoöuü which is encode with x-www-form-urlencoded to sendMail?text=a%E4o%F6u%FC

The content of the mail is a?o?u?.

Mail API is Apache Commons Email.

How can I get the right character encoding to the mail?

skaffman
  • 398,947
  • 96
  • 818
  • 769
Chris
  • 7,864
  • 1
  • 27
  • 38

1 Answers1

0

You should encode the parameter using UTF-8 before applying the URL encoding.

Andreas Veithen
  • 8,868
  • 3
  • 25
  • 28