Given:
String email1 = "[email protected]";
// legal email address according to wikipedia [1]
String email2 = "\"()<>[]:,;@\\\"!#$%&'*+-/=?^_`{}| ~.a\"@example.org";
What is the best/correct way to create a mailto: URI (in the form of a String object)?
I tried:
String uri = new URI("mailto", the_email_address, null).toString();
This is the closest I got, but it does not encode the question-mark (?) in the local part of the email address, but according to RFC 6068 it should. It also fails on examples in the RFC, like "not@me"@example.org or [email protected].
[1] Valid_email_addresses examples
PS: There is some useful information in Should plus be encoded in mailto: hyperlinks?
I settled for this as a solution:
import org.apache.http.client.utils.URIBuilder;
// from Apache HttpClient
// maven group: org.apache.httpcomponents artifact: httpclient
String emailURL = new URIBuilder().setScheme("mailto").setPath(the_email_address).toString();