title: Embed a link in email message for file attached using JavaMail doesn't work
body: <p>I'm trying to embed a link in email for a file attached in email message using JavaMail APi like  <a href="https://stackoverflow.com/questions/24036058/how-to-embed-a-link-in-email-message-for-file-attached-in-email-using-javamail-a">here</a>.
  This is my code:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>MimeMultipart multipart = new MimeMultipart("related");
  
  BodyPart messageBodyPart = new MimeBodyPart();
  String attachment = "/path/test.pdf";
  File fAtachh = new File(attachment);
  
  String htmlText = "&lt;a href='cid:file'&gt;test.pdf&lt;/a&gt;";
  messageBodyPart.setContent(htmlText, "text/html"); 
  multipart.addBodyPart(messageBodyPart);
  
  MimeBodyPart messageBodyPartAttach = new MimeBodyPart();
  
  try {
   messageBodyPartAttach.attachFile(fAtachh);
  } catch (IOException e) {
   logger.info("Exception" + e.getMessage());
  }
  
  messageBodyPartAttach.setContentID("&lt;file&gt;");
  
  multipart.addBodyPart(messageBodyPartAttach);
  
  message.setContent(multipart);</code></pre>
  </div>
  </div>
  </p>
  
  <p>The problem is that link doesn't work:</p>
  
  <p><a href="https://i.stack.imgur.com/2vrTP.png" rel="nofollow noreferrer">ErrorLink</a></p>
  
  <p>If change the last code by:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>MimeMultipart multipart = new MimeMultipart("related");
  
  MimeBodyPart messageBodyPart = new MimeBodyPart();
  
  String attachment = "/path/test.pdf";
  String htmlText = "&lt;a href='cid:file'&gt;test.pdf&lt;/a&gt;";
  
  messageBodyPart.setContent(htmlText, "text/html");
  multipart.addBodyPart(messageBodyPart);
  
  MimeBodyPart messageBodyPartAttach = new MimeBodyPart();
  DataSource fds = new FileDataSource
             (attachment);
  messageBodyPartAttach.setDataHandler(new DataHandler(fds));
  messageBodyPartAttach.setHeader("Content-ID","&lt;file&gt;");
  
  multipart.addBodyPart(messageBodyPartAttach);
  
  message.setContent(multipart);</code></pre>
  </div>
  </div>
  </p>
  
  <p>The link Works but the file name and extension are wrong:</p>
  
  <p><a href="https://i.stack.imgur.com/C8if8.png" rel="nofollow noreferrer">WrongFileName</a></p>
  
  <p>I've tried to change the file name by method:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>messageBodyPartAttach.setFileName("test.pdf");</code></pre>
  </div>
  </div>
  </p>
  
  <p>but if I set the file name, the link doesn´t work like in the first code.</p>
  
  <p>Any suggestion?</p>
  
  <p>Thanks!</p>