How can i save the attachments of a mail
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Brunet_Sebastien
Posted On:   Tuesday, January 14, 2003 12:04 AM

I want to save the attachments of an email I have this code, but he doesn't work, can you help me it's very urgent. Thank You import java.io.*; import java.net.InetAddress; import java.util.*; import java.lang.*; import javax.mail.*; import javax.mail.internet.*; import javax.activation.*; public class LireMail { public static void Lire(String v_host,String v_username,String v_password) throws Exception { String host = v_host; String username = v_username; String password = v_password; Object o; // Create empty properties Properties props = new Properties(); // Get session Session sessi   More>>

I want to save the attachments of an email
I have this code, but he doesn't work, can you help me it's very urgent. Thank You

			
import java.io.*;
import java.net.InetAddress;
import java.util.*;
import java.lang.*;

import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;


public class LireMail {
public static void Lire(String v_host,String v_username,String v_password) throws Exception {
String host = v_host;
String username = v_username;
String password = v_password;
Object o;

// Create empty properties
Properties props = new Properties();

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

// Get the store
Store store = session.getStore("pop3");

// Connect to store
store.connect(host, username, password);

// Get folder
Folder folder = store.getFolder("INBOX");

// Open read-only
folder.open(Folder.READ_WRITE);

BufferedReader reader = new BufferedReader (
new InputStreamReader(System.in));

// Get directory
Message message[] = folder.getMessages();

for (int i=0, n=message.length; i
Multipart mp = (Multipart)message[i].getContent();
for (int j=0, m=mp.getCount();j
Part part = mp.getBodyPart(j);
File file = new File(part.getFileName());

FileOutputStream fos = new FileOutputStream(file);
BufferedOutputStream bos = new BufferedOutputStream(fos);
BufferedInputStream bis = new BufferedInputStream(part.getInputStream());

int aByte;
while ((aByte = bis.read()) != -1) {
bos.write(aByte);
}
bos.flush();
bos.close();
bis.close();

}
}

// Close connection
folder.close(false);
store.close();
}
}

   <<Less

Re: How can i save the attachments of a mail

Posted By:   John_Zukowski  
Posted On:   Friday, January 31, 2003 09:07 PM

Check the FAQ. Already shows how.
About | Sitemap | Contact