if (multipart == null) { multipart = new MimeMultipart(); }  MimeBodyPart part = new MimeBodyPart();  if (obj instanceof String) { part.setContent(obj.toString(), "text/plain"); } else if (obj instanceof File) { FileDataSource source = new FileDataSource((File) obj);  part.setDataHandler(new DataHandler(source)); } else if (obj instanceof MimePart) { MimePartDataSource source = new MimePartDataSource((MimePart) obj);  part.setDataHandler(new DataHandler(source)); }   if (filename != null && filename != Undefined.instance) { try { part.setFileName(filename.toString()); } catch (Exception x) {  } }  multipart.addBodyPart(part);
    public void addPart(Object obj, Object filename) throws Exception {        if (obj == null || obj == Undefined.instance) {            throw new IOException("mail.addPart called with wrong number of arguments.");        }        if (multipart == null) {            multipart = new MimeMultipart();        }        MimeBodyPart part = new MimeBodyPart();        if (obj instanceof String) {            part.setContent(obj.toString(), "text/plain");        } else if (obj instanceof File) {            FileDataSource source = new FileDataSource((File) obj);            part.setDataHandler(new DataHandler(source));        } else if (obj instanceof MimePart) {            MimePartDataSource source = new MimePartDataSource((MimePart) obj);            part.setDataHandler(new DataHandler(source));        }        // check if an explicit file name was given for this part        if (filename != null && filename != Undefined.instance) {            try {                part.setFileName(filename.toString());            } catch (Exception x) {                // FIXME: error setting file name ... should we ignore this or throw an exception?            }        }        multipart.addBodyPart(part);    }