How to use imap in javamail, fix error javax.mail.AuthenticationFailedException

1

As the title says I am trying to implement the email receipt in an Android apk using the javamail library (imap), but it turns out that I always get an error javax.mail.AuthenticationFailedException , the user has access to imap, help me solve it?, I leave here the code

package apk.cjam.intermail;
import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import com.sun.mail.imap.IMAPFolder;
import java.io.IOException;
import java.util.Properties;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.NoSuchProviderException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Store;
public class recibemail extends AppCompatActivity {
private Session session;
private Folder folder;
private Message message;
private Store store;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_recibemail);
    Button recivir = (Button) findViewById(R.id.Recibir);

}
public void recivecorreo(View view)  {
    try {
        Properties props = new Properties();
        props.put("mail.imap.host", "192.168.246.1");
        props.put("mail.imap.port", "143");
        session = Session.getDefaultInstance(props,
                new javax.mail.Authenticator() {
                    //Authenticating the password
                    protected PasswordAuthentication getPasswordAuthentication() {
                        return new PasswordAuthentication("[email protected]", "javier08");
                    }
                });
        store = session.getStore("imaps");
        store.connect();
        folder= store.getFolder("INBOX");
        folder.open(Folder.READ_ONLY);
        Message[] messages = folder.getMessages();
        for (int i = 0,n = messages.length; i < n;i++){
            Log.i("","-------------------------------");
            Log.i("","Email number "+ (i+1));
            Log.i("","Asunto " + message.getSubject());
            Log.i("","De " + message.getFrom());
            Log.i("","Texto " + message.getContent().toString());
        }
        folder.close(false);
        store.close();
    } catch (NoSuchProviderException e) {
        e.printStackTrace();

    } catch (MessagingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

}



}
    
asked by cjamdeveloper 13.03.2017 в 21:38
source

0 answers