Gmail in android with oauth2
<p>I want to create an app to send mail on gmail using oauth 2. I follow  <a href="https://java.net/projects/javamail/pages/OAuth2" rel="nofollow">OAuth2 Support java mail</a>, but app can't run. I have accesstoken from <a href="https://developers.google.com/oauthplayground/" rel="nofollow">OAuth 2.0 Playground</a>. Thank you.</p>

<pre><code>Properties props = new Properties();
props.put("mail.imap.ssl.enable", "true");
props.put("mail.imap.auth.mechanisms", "XOAUTH2");
session = Session.getInstance(props);
session.setDebug(true);
try {
    store = session.getStore("imap");
    store.connect("imap.gmail.com", "pysyren@gmail.com", "access token here");
} catch (NoSuchProviderException e) {
    e.printStackTrace();
} catch (MessagingException e) {
    e.printStackTrace();
}

RetreiveFeedTask task = new RetreiveFeedTask();
task.execute();



class RetreiveFeedTask extends AsyncTask&lt;String, Void, String&gt; {

    @Override
    protected String doInBackground(String... params) {

        try{
            Message message = new MimeMessage(session);
            message.setFrom(new InternetAddress("pysyren@gmail.com"));
            message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("vckhanh2310@gmail.com"));
            message.setSubject("Test");
            message.setContent("android", "text/html; charset=utf-8");
            Transport.send(message);
            Toast.makeText(getApplicationContext(), "Dangsend", Toast.LENGTH_LONG).show();
        } catch(MessagingException e) {
            e.printStackTrace();
        } catch(Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    protected void onPostExecute(String result) {
        pdialog.dismiss();

        Toast.makeText(getApplicationContext(), "Message sent", Toast.LENGTH_LONG).show();
    }
</code></pre>