try { FileDataSource fds = new FileDataSource( filePath ); mbp.setDataHandler( new DataHandler( fds ) ); mbp.setFileName( fds.getFile().getName() ); mp.addBodyPart( mbp ); } catch ( MessagingException e ) { e.printStackTrace(); }
ContentTypeFileTypeMap ctfm = ContentTypeFileTypeMap.getInstance();  String contentType = ctfm.getContentTypeFor( fileName ); mbp.setDataHandler( new DataHandler( new InputStreamDataSource( in, contentType ) ) ); mbp.setFileName( fileName ); mp.addBodyPart( mbp );
    public void addAttachment( String filePath )    {        MimeBodyPart mbp = new MimeBodyPart();        try        {            FileDataSource fds = new FileDataSource( filePath );            mbp.setDataHandler( new DataHandler( fds ) );            mbp.setFileName( fds.getFile().getName() );            mp.addBodyPart( mbp );        }        catch ( MessagingException e )        {            e.printStackTrace();        }    }