How to get email from gmail android

I am new to Android programming.

I received my application with a Gmail account sending emails. Now I need to learn how to receive new letters from G-mail? Or at least how do I get a notification that there is new mail in my inbox?

I don’t want to use the Gmail application from the market or the built-in Android email application or so ... I create my own application that manages Gmail accounts (for example, a kind of widget in my own application).

+4
source share
2 answers

To implement this feature, you first need to connect to the gmail server, then you need to check the inbox for new messages. If find, send a notification to the user using the NotificationManager. follow these links http://www.jondev.net/articles/Sending_Emails_without_User_Intervention_%28no_Intents%29_in_Android and another link

Sending email on Android using the JavaMail API without using a standard / built-in application

+3
source

Try the following:

Properties props = new Properties(); //IMAPS protocol props.setProperty("mail.store.protocol", "imaps"); //Set host address props.setProperty("mail.imaps.host", imaps.gmail.com); //Set specified port props.setProperty("mail.imaps.port", "993β€³); //Using SSL props.setProperty("mail.imaps.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); props.setProperty("mail.imaps.socketFactory.fallback", "false"); //Setting IMAP session Session imapSession = Session.getInstance(props); Store store = imapSession.getStore("imaps"); //Connect to server by sending username and password. //Example mailServer = imap.gmail.com, username = abc, password = abc store.connect(mailServer, account.username, account.password); //Get all mails in Inbox Forlder inbox = store.getFolder("Inbox"); inbox.open(Folder.READ_ONLY); //Return result to array of message Message[] result = inbox.getMessages(); 
+2
source

All Articles