title: javax.mail.internet.ParseException: Expected "/", got files
body: <p>I am getting an error while trying to send an email with file attachment : </p>
  
  <pre><code>javax.mail.internet.ParseException: Expected '/', got files
      at javax.mail.internet.ContentType.&lt;init&gt;(ContentType.java:102)
      at javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1331)
      at javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1021)
      at javax.mail.internet.MimeMultipart.updateHeaders(MimeMultipart.java:419)
      at javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1354)
      at javax.mail.internet.MimeMessage.updateHeaders(MimeMessage.java:2107)
      at javax.mail.internet.MimeMessage.saveChanges(MimeMessage.java:2075)
      at javax.mail.Transport.send(Transport.java:123)
  </code></pre>
  
  <p>The code below : </p>
  
  <pre><code>@Override
      public void execute(String filePath) {
          try {            
              Properties props = new Properties();                       
              props.put("mail.smtp.host", "smtp.gmail.com");
              props.put("mail.smtp.socketFactory.port", "465");
              props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
              props.put("mail.smtp.auth", "true");
              props.put("mail.smtp.port", "465");                                 
  
              Session mailSession = Session.getInstance(props, new Authenticator() {
                  @Override
                  protected PasswordAuthentication getPasswordAuthentication() {                    
                      return new PasswordAuthentication(GMAIL_ACCOUNT, GMAIL_PASSWORD);
                  }
              });                    
              //We create a new mail message
              Message msg = new MimeMessage(mailSession);
              msg.setFrom(new InternetAddress("esombugma@gmail.com"));
              //We constitute the list of recipients
              List&lt;InternetAddress&gt; recipList = new ArrayList&lt;&gt;();
              for(String address : this.getRecipients()) {
                  recipList.add(new InternetAddress(address));
              }            
              InternetAddress[] iaTab = new InternetAddress[recipList.size()];
              iaTab = recipList.toArray(iaTab);
              msg.setRecipients(Message.RecipientType.TO, iaTab);
              msg.setSubject(this.getSubject());
              msg.setSentDate(new Date());
              //Create multi-part
              Multipart multipart = new MimeMultipart();            
              //Create a message part
              MimeBodyPart msgBodyPart = new MimeBodyPart();
              msgBodyPart.setContent(this.getMessage(), this.getSubject());
              multipart.addBodyPart(msgBodyPart);
              //Adds attachment
              if((new File(filePath)).exists()) {
                  MimeBodyPart attachment = new MimeBodyPart();
                  try {
                      attachment.attachFile(new File(filePath));
                  } catch (IOException ex) {
                      Logger.getLogger(EmailSender.class.getName()).log(Level.SEVERE, null, ex);
                  }                
                  attachment.setFileName((new File(filePath)).getName());
                  multipart.addBodyPart(attachment);
              }            
              msg.setContent(multipart);            
              Transport.send(msg);
          } catch (MessagingException ex) {
              Logger.getLogger(EmailSender.class.getName()).log(Level.SEVERE, null, ex);
          }        
      }
  </code></pre>
  
  <p>And the code that generate the file is here : </p>
  
  <pre><code>public String getMissingReportName() {
          SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhh");
          return "C://Report//Report_" + sdf.format(new Date()) + ".xls";
  }
  </code></pre>
  
  <p>Then a sample report file should be : <code>Report_20130512</code> for example.</p>
  
  <p>Can someone explain to me what could be the orrigine of this error.
  Thank you.</p>