Yaee Galera, estou fazendo um programa p/ conectar ao servidor de e-mail utilizando o protocolo imap, mas ñ esta dando certo. O que poderia ser este erro???
Erro retornado:
DEBUG: setDebug: JavaMail version 1.4.3
DEBUG: getProvider() returning javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc]
DEBUG: mail.imap.fetchsize: 16384
DEBUG: mail.imap.statuscachetimeout: 1000
DEBUG: mail.imap.appendbuffersize: -1
DEBUG: mail.imap.minidletime: 10
DEBUG: trying to connect to host “servidor.cptec.inpe.br”, port 993, isSSL true
- OK servidor.cptec.inpe.br Cyrus IMAP4 v2.2.12-Invoca-RPM-2.2.12-8.1.RHEL4 server ready
A0 CAPABILITY - CAPABILITY IMAP4 IMAP4rev1 ACL QUOTA LITERAL+ MAILBOX-REFERRALS NAMESPACE UIDPLUS ID NO_ATOMIC_RENAME UNSELECT CHILDREN MULTIAPPEND BINARY SORT THREAD=ORDEREDSUBJECT THREAD=REFERENCES ANNOTATEMORE IDLE AUTH=DIGEST-MD5 AUTH=LOGIN AUTH=CRAM-MD5 AUTH=NTLM AUTH=GSSAPI AUTH=PLAIN SASL-IR LISTEXT LIST-SUBSCRIBED X-NETSCAPE
A0 OK Completed
IMAP DEBUG: AUTH: DIGEST-MD5
IMAP DEBUG: AUTH: LOGIN
IMAP DEBUG: AUTH: CRAM-MD5
IMAP DEBUG: AUTH: NTLM
IMAP DEBUG: AUTH: GSSAPI
IMAP DEBUG: AUTH: PLAIN
DEBUG: protocolConnect login, host=servidor.cptec.inpe.br, user=usuario, password=
A1 AUTHENTICATE PLAIN
YXJtc29sbzEAYXJtc29sbzEAQXJtc29sbzE=
A1 NO generic failure
Exception in thread “main” javax.mail.AuthenticationFailedException: generic fai
lure
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:613)
at javax.mail.Service.connect(Service.java:291)
at saveAttachments.main(saveAttachments.java:30)
segue o codigo:
import java.io.*;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
public class saveAttachments {
public static void main (String args[]) throws Exception {
String host = "servidor.cptec.inpe.br";
String username = "usuario";
String password = "senha";
int port = 993;
Authenticator auth = new MyAuthenticator();
// Create empty properties
Properties props = new Properties();
props.put("mail.imap.host", host);
props.put("mail.imap.auth", "true");
// Get session
Session session = Session.getDefaultInstance(props, auth);
// Session session = Session.getDefaultInstance(props, null);
session.setDebug(true);
// Get the store
Store store = session.getStore("imaps");
// Connect to store
store.connect(host, port, username, password);
// Get folder
Folder folder = store.getFolder("INBOX");
// Open read-only
folder.open(Folder.READ_ONLY);
BufferedReader reader = new BufferedReader (
new InputStreamReader(System.in));
// Get directory
Message message[] = folder.getMessages();
for (int i=0, n=message.length; i<n; i++) {
// Display from field and subject
System.out.println(i + ": " + message[i].getFrom()[0]
+ "\t" + message[i].getSubject());
System.out.println("Do you want to read message? [YES to read/QUIT to end]");
String line = reader.readLine();
if ("YES".equals(line)) {
// Display message content
System.out.println(message[i].getContent());
} else if ("QUIT".equals(line)) {
break;
}
/*
Multipart mp = (Multipart)message.getContent();
for (int i=0, n=multipart.getCount(); i<n; i++) {
Part part = multipart.getBodyPart(i));
String disposition = part.getDisposition();
if ((disposition != null) &&
((disposition.equals(Part.ATTACHMENT) ||
(disposition.equals(Part.INLINE))) {
saveFile(part.getFileName(), part.getInputStream());
}
}
*/
}
// Close connection
folder.close(false);
store.close();
}
public static class MyAuthenticator extends Authenticator {
public PasswordAuthentication getPasswordAuthentication() {
String username, password;
username = "usuario";
password = "senha";
return new PasswordAuthentication(username, password);
}
}
}