JavaMail - result file take the whole path of file

I am using Java Mail, and it is working fine. I have a problem though, when I open the attachment, it contains the file path.

For example, the attachments should be Result.zip, and then I should get the files if I unzip them. On the contrary, I am getting the folder as a an attachment, that I have to be clicked number of times to get to result.zip.

As you can see in the code, it starts with the directory/application server/application name/and then the resultant files.

How can I get rid of the path from the resultant files, thanks.

Here is my code:

publicvoid sendMail()

{

try

{

String smtpHost ="mail.isp.com";

String from ="abc@def.com" ;

String to = getUserEmail() ;

String attachName ="result.zip";

String filename ="C:\\JBoss\\jboss-4.0.5.GA\\bin\\Fastran<br clear="all" />" + getUserEmail() +"<br clear="all" />Result.zip" ;

// Get system properties

Properties props = System.getProperties();

// Setup mail server

props.put("mail.smtp.host", smtpHost);

// Get session

Session session = Session.getDefaultInstance(props,null);

// Define message

MimeMessage message =new MimeMessage(session);

message.setFrom(new InternetAddress(from));

message.addRecipient(Message.RecipientType.TO,

new InternetAddress(to));

message.setSubject("Resulting files for Fastran Application");

// Create the multi-part

Multipart multipart =new MimeMultipart();

// Create part one

BodyPart messageBodyPart =new MimeBodyPart();

// Fill the message

messageBodyPart.setText("Please find attached the resulting files for Fastran Application");

// Add the first part

multipart.addBodyPart(messageBodyPart);

// Part two is attachment

messageBodyPart =new MimeBodyPart();

DataSource source =new FileDataSource(filename);

messageBodyPart.setDataHandler(new DataHandler(source));

messageBodyPart.setFileName(filename);

// Add the second part

multipart.addBodyPart(messageBodyPart);

// Put parts in message

message.setContent(multipart);

// Send message

Transport.send(message);

}

catch(Exception e)

{

System.out.println("Exception : "+ e.getMessage());

}

}

Message was edited by:

NasirMunir

Message was edited by:

NasirMunir

[3876 byte] By [NasirMunira] at [2007-11-26 23:07:29]
# 1
Nothing to do with JavaMail, but here's what I think you were asking about:messageBodyPart.setFileName(new File(filename).getName());
DrClapa at 2007-7-10 14:01:41 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

Dr, thanks for help.

My problem is still there. Now the resulting files are encapsulated in a folder name called "Result.zip", and followed by JBoss - jboss-4.0.5.GA - bin - Fastran - and so on till I get my original files.

I want to get rid of this long path to get to my files.

Can you suggest something ?

NasirMunira at 2007-7-10 14:01:41 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3
my bad. The problem is not with the send mail, rather in my other method - zip().Sorry for that
NasirMunira at 2007-7-10 14:01:41 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...