0

I am writing a large Java Application in which I would like to include a "Send Email" button. All it does is open a mailto url with the appropriate headers.

The only difficulty I am having is parsing the input strings so that they are formatted appropriately, for example: mailto:someone@somewhere.net?subject=This is the subject needs to become mailto:someone@somewhere.net?subject=This%20is%20the%20subject

Peaches491
  • 1,239
  • 15
  • 27

2 Answers2

2

You can try URLEncoder, specifically the encode method that can be found here.

alexcoco
  • 6,657
  • 6
  • 27
  • 39
  • 3
    *The space character " " is converted into a plus sign "+".* – Michael Myers Jun 02 '11 at 15:30
  • 1
    The answer is actually given in [the question that red eyes dev linked](http://stackoverflow.com/questions/724043/http-url-address-encoding-in-java), though it's not an exact duplicate. – Michael Myers Jun 02 '11 at 15:36
  • That looks and sounds like exactly what I need, but according to eclipse, its depreciated. =/ – Peaches491 Jun 02 '11 at 15:43
  • There are two, you have to use the one that's `encode(String, String)`. Haven't tried but I think you should be able to pass one of [these](http://download.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html) according to the docs. – alexcoco Jun 02 '11 at 15:46
1

You most likely need to "URLEncode" (translates the space characters (' ') to %20.

See this document: http://download.oracle.com/javase/1.5.0/docs/api/java/net/URLEncoder.html

qxotk
  • 2,384
  • 5
  • 24
  • 39