I have an application that downloads the attachments that are sent in a certain email and works perfectly.
There was a need to do the same thing in another email. Both are gmail.
However, when I read the inbox of the second email, all attachments come as null and it does not make 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'm trying to download .XML files
I can not understand why the first email works perfectly and in the second, which is the same, come null.