Java mailto Illegal character colon? -
im trying send email attachment, keeps saying:
exception in thread "awt-eventqueue-0" java.lang.illegalargumentexception: illegal character in opaque part @ index 64: mailto:recipient@mailserver.com?subject=thepdffile&attachment=c:\users\rascal\appdata\local\temp\freelancerlist-16-12-2014_09-227568200505392670736.doc
java code:
desktop desktop = desktop.getdesktop(); string message = "mailto:recipient@mailserver.com?subject=thepdffile&attachment=\""+path; urlencoder.encode(message, "utf-8"); uri uri = uri.create(message); desktop.mail(uri);
should colon right? why???
you're calling urlencoder.encode
, ignoring result. suspect trying achieve this:
string encoded = urlencoder.encode(message, "utf-8"); uri uri = uri.create(encoded);
... although @ point you'll have encoded colon after mailto
part well. suspect really want like:
string query = "subject=thepdffile&attachment=\""+path; string prefix = "mailto:recipient@mailserver.com?"; uri uri = uri.create(prefix + urlencoder.encode(query, "utf-8"));
or encoding values:
string query = "subject=" + urlencoder.encode(subject, "utf-8"); + "&attachment=" + urlencoder.encode(path, "utf-8")); uri uri = uri.create("mailto:recipient@mailserver.com?" + query);
... or create uri
various different parts separately, of course.
Comments
Post a Comment