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

