java - How to add clicable a href to attachment of email sended from javax.mail -
i sending email javax.mail.
i sending attachments (some files, example pdf.)
i want add link attachment email body this:
dear user, can download file in attachment link "download"
my code is:
string cidlinks = "<br>"; int counter = 0; (string attachments : email.pathtoattachments) { string ciddata = "<data" + (counter) + ">"; mimebodypart mimebodypart = buildmimebodypart(attachments, ciddata); multipart.addbodypart(mimebodypart); counter++; cidlinks += "<a href='cid:" + ciddata + "'> " + mimebodypart.getfilename() + "</a>" + "<br>"; }
and mimebuilder is:
private mimebodypart buildmimebodypart(string path, string id) { mimebodypart emailmemebodypart = new mimebodypart(); try { datasource source = new filedatasource(path); emailmemebodypart.setdatahandler(new datahandler(source)); emailmemebodypart.setfilename(source.getname()); emailmemebodypart.setcontentid(id); } catch (exception e) { system.out.println("err: " + e.getmessage()); } return emailmemebodypart; }
i have problems links generated in:
cidlinks += "<a href='cid:" + ciddata + "'> " + mimebodypart.getfilename() + "</a>" + "<br>";
when click on link in email, not start download file.
files in attachments sucessfuly sended.
can me? problem? how can download file attachment link?
thank you.
note: email content valid hmtl format.
Comments
Post a Comment