title: Java Mail API - Encoding problems
body: <p>I'm using Java Mail API and I'm trying to send an email through Gmail's SMTP.
  How my program works:
  java.util.Scanner class is used to get user input - I'm asking user for various parameters to be used in mail sending class; which does the following:</p>
  
  <pre><code>Message mailMessage = new MimeMessage(session);
  mailMessage.setFrom(new InternetAddress("example@example.com"));
  mailMessage.setRecipients(Message.RecipientType.TO,InternetAddress.parse(mail.getTo()));
  mailMessage.setSubject(mail.getSubject());
  mailMessage.setText(mail.getMessage());
  Transport.send(mailMessage);
  </code></pre>
  
  <p>Everything works as long as I use ASCII symbols/ chars. But whenever I want to use "country-specific" characters - like [õäöü] - I get bunch of weird-looking symbols...</p>
  
  <p>Techniques I've used so far(which don't work for me):</p>
  
  <pre><code>setHeader("Content-Type", "text/plain; charset=UTF-8");
  setHeader("Content-Encoding","ISO-8859-9");
  setContent(message, "text/plain; charset=iso-8859-2");
  </code></pre>
  
  <p>Note: everything is displayed correctly inside an IDE when System.out.println() is performed to display the message to be sent.</p>
  
  <p>EDIT: e.x. when sent message body is [õäöü]
  It's displayed [ä„”?] in Gmail.</p>
  
  <p>EDIT: When <code>mailMessage.setText(MimeUtility.encodeText(mail.getMessage(), "UTF-8", "Q"));</code> is used, then the output in Gmail is following: </p>
  
  <pre><code>"=?UTF-8?Q?=C3=A4=E2=80=9E=E2=80=9D=EF=BF=BD;=0D=0A?="
  </code></pre>
  
  <p>ANOTHER EDIT: Interestingly, when I do: <code>mailMessage.setText(strVar + "õäöü", "ISO-8859-1");</code>
  It actually appends "õäöü" nicely in my email (but the first part[strVar] of the string is still full of ?'s and []'s).</p>