title: Send File as an attachment or inline using Spring JavaMailSender
body: <p>i have created a simple spring application which sends an email to the user. this seems to be perfectly working with "SimpleMailMessage" (the whole message is going as a plain text). What i want is to send some file as an attachment, so i tried to use javax.mail.internet.MimeMessage but getting some wired Error which i am not able to trace down. Below is my snippet</p>
  
  <pre><code>try {
              javax.mail.internet.MimeMessage message = mailSender.createMimeMessage();
              MimeMessageHelper helper = new MimeMessageHelper(message,true);
              helper.setTo(employee.getEmailId());
              helper.setFrom("abc@xyz.com");
              helper.setText(mailMessage, true);
              helper.setSubject(subject);
              FileSystemResource res = new FileSystemResource(new File("C:/software/Koala.jpeg"));
              helper.addAttachment("happyBirthday", res);
              mailSender.send(message);
          } catch (MessagingException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
  </code></pre>
  
  <p>The Error is :</p>
  
  <pre><code>Caused by: java.lang.LinkageError: loader constraint violation: when resolving method "javax.mail.internet.MimeBodyPart.setDataHandler(Ljavax/activation/DataHandler;)V" the class loader (instance of org/jboss/classloader/spi/base/BaseClassLoader) of the current class, org/springframework/mail/javamail/MimeMessageHelper, and the class loader (instance of org/jboss/classloader/spi/base/BaseClassLoader) for resolved class, javax/mail/internet/MimeBodyPart, have different Class objects for the type n/DataHandler;)V used in the signature
      at org.springframework.mail.javamail.MimeMessageHelper.addAttachment(MimeMessageHelper.java:997)
      at org.springframework.mail.javamail.MimeMessageHelper.addAttachment(MimeMessageHelper.java:1077)
      at org.springframework.mail.javamail.MimeMessageHelper.addAttachment(MimeMessageHelper.java:1047)
      at Example1.sendEmail(Example1.java:89)
  </code></pre>
  
  <p>Any help would really be appreciated.</p>