0
I have an application that downloads the attachments that are sent in a certain e-mail and works perfectly.
There arose the need to do the same thing in another email. The two are gmail.
However, when I read the inbox of the second email, all attachments come as null and this is not making any sense to me.
Code:
public static void main(String[] args) {
try {
Email email = new Email();
Store store = email.conectar(ConfigEmail.host, ConfigEmail.email, ConfigEmail.senha);
Folder inbox = email.selecionaPasta(store);
Message[] mensagens = email.mensagens(inbox);
for (int i = 0; i < mensagens.length; i++) {
System.out.println("Lendo: " + mensagens[i].getFrom()[0]);
if(email.hasAttachments(mensagens[i])) {
Multipart mp = (Multipart) mensagens[i].getContent();
for (int j = 1; j <= mp.getCount() -1; j++) {
Part part = mp.getBodyPart(j);
// Exibe -1 para todos anexos
System.out.println(part.getSize());
// Exibe multipart/MIXED
System.out.println(part.getContentType());
// Exibe um endereco de memória
System.out.println(part.getContent());
//Exibe null
System.out.println(part.getFileName());
}
}
}
inbox.close(false);
store.close();
} catch (MessagingException | IOException e) {
e.printStackTrace();
}
}
I am trying to download . XML files
I can not understand why the first e-mail works perfectly and the second, which is the same thing, come null.
Could you separate the answer (in a new post) from the question?
– rray
dlosi, it’s cool that you share the solution found, but to be perfect really, it would be nice if you [Dit] your question, cutting out the solution, and pasting in the correct field (the answer field). Then you can mark your own answer as accepted, so the post is marked as solved.
– Bacco
I did. Thanks for the tips
– dlosi