title: Send email through with attach files
body: <p>I used the following code to send mail through gmail. I got that code from this site itself. I want to attach a file to the mail that I send. Can I do that with this code? what part of this code should I edit? Can I send sql backup file(xxx.sql) through email?</p>
  
  <pre><code>    try{
  
      Properties props = new Properties();
      props.put("mail.smtp.host", "smtp.gmail.com"); // for gmail use smtp.gmail.com
      props.put("mail.smtp.auth", "true");
      props.put("mail.debug", "true"); 
      props.put("mail.smtp.starttls.enable", "true");
      props.put("mail.smtp.port", "465");
      props.put("mail.smtp.socketFactory.port", "465");
      props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
      props.put("mail.smtp.socketFactory.fallback", "false");
  
      Session mailSession = Session.getInstance(props, new javax.mail.Authenticator() {
  
          protected PasswordAuthentication getPasswordAuthentication() {
              return new PasswordAuthentication("ravinduis34@gmail.com", "creative12533");
          }
      });
  
      mailSession.setDebug(true); // Enable the debug mode
  
      Message msg = new MimeMessage( mailSession );
  
      //--[ Set the FROM, TO, DATE and SUBJECT fields
      msg.setFrom( new InternetAddress( "ravinduis34@gmail.com" ) );
      msg.setRecipients( Message.RecipientType.TO,InternetAddress.parse("ravindusisira@gmail.com") );
      msg.setSentDate( new Date(232323));
      msg.setSubject( "Hello World!" );
  
      //--[ Create the body of the mail
      msg.setText( "Hello from my first e-mail sent with JavaMail" );
  
      //--[ Ask the Transport class to send our mail message
      Transport.send( msg );
  
  }catch(Exception E){
      System.out.println( "Oops something has gone pearshaped!");
      System.out.println( E );
  }
  </code></pre>