3

I'm trying send an Email by clicking a button and the sending mail is a user given identification code. But the e-mail is not sent correctly. Can anyone help me to solve this.

I created my app by according to this :-

Sending Email in Android using JavaMail API without using the default/built-in app

This is the logcat messages i'm getting.

03-16 01:51:13.592    1913-1913/com.example.dushani.emailsender I/art﹕ Not late-enabling -Xcheck:jni (already on)
03-16 01:51:13.688    1913-1928/com.example.dushani.emailsender D/OpenGLRenderer﹕ Render dirty regions requested: true
03-16 01:51:13.711    1913-1913/com.example.dushani.emailsender D/﹕ HostConnection::get() New Host Connection established 0xae2eadc0, tid 1913
03-16 01:51:13.724    1913-1913/com.example.dushani.emailsender D/Atlas﹕ Validating map...
03-16 01:51:13.750    1913-1925/com.example.dushani.emailsender I/art﹕ Background sticky concurrent mark sweep GC freed 1795(95KB) AllocSpace objects, 0(0B) LOS objects, 35% free, 402KB/623KB, paused 16.584ms total 23.060ms
03-16 01:51:13.909    1913-1928/com.example.dushani.emailsender D/﹕ HostConnection::get() New Host Connection established 0xa6e3f3f0, tid 1928
03-16 01:51:13.925    1913-1928/com.example.dushani.emailsender I/OpenGLRenderer﹕ Initialized EGL, version 1.4``
03-16 01:51:13.999    1913-1925/com.example.dushani.emailsender I/art﹕ Background partial concurrent mark sweep GC freed 1958(107KB) AllocSpace objects, 0(0B) LOS objects, 53% free, 436KB/948KB, paused 1.878ms total 189.812ms
03-16 01:51:14.019    1913-1928/com.example.dushani.emailsender D/OpenGLRenderer﹕ Enabling debug mode 0
03-16 01:51:14.043    1913-1928/com.example.dushani.emailsender W/EGL_emulation﹕ eglSurfaceAttrib not implemented
03-16 01:51:14.044    1913-1928/com.example.dushani.emailsender W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa6e0df20, error=EGL_SUCCESS
03-16 01:51:47.305    1913-1928/com.example.dushani.emailsender W/EGL_emulation﹕ eglSurfaceAttrib not implemented
03-16 01:51:47.305    1913-1928/com.example.dushani.emailsender W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa6e0df20, error=EGL_SUCCESS
03-16 01:52:30.073    1913-1925/com.example.dushani.emailsender I/art﹕ Background sticky concurrent mark sweep GC freed 1881(109KB) AllocSpace objects, 0(0B) LOS objects, 23% free, 723KB/948KB, paused 1.427ms total 111.164ms
Community
  • 1
  • 1
  • 1
    Paste your code here! – T D Nguyen Mar 15 '15 at 21:20
  • This looks like an OGL problem, not e-mail. – m0skit0 Mar 15 '15 at 21:22
  • Can you please tell me what is an OGL problem.And is there any way to solve this problem. – Ishara Madushani Mar 16 '15 at 05:58
  • I'm developing an app using android studio. First user have to register to the app by giving him or her email and password.After that user have to give a secret code and that code must be send to the him/her email account (Both sender and the receiver email address are same).Please if you have any better way to do this can you share any snippet code. – Ishara Madushani Mar 16 '15 at 06:15

1 Answers1

2

I use this method,

Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("message/rfc822");

    String possibleEmail = new String();
    mailArray = new String[]{getString(R.string.mail), possibleEmail};

    Pattern emailPattern = Patterns.EMAIL_ADDRESS;
    Account[] accounts = AccountManager.get(getBaseContext()).getAccounts();

    for (Account account : accounts) {
        if (emailPattern.matcher(account.name).matches()) {
            possibleEmail = account.name;
        }
    }

    if(sendToMeCheckBox.isChecked()){

        mailArray [1] = possibleEmail;
    }

    intent.putExtra(Intent.EXTRA_EMAIL, mailArray );
    intent.putExtra(Intent.EXTRA_SUBJECT, "Some random subject");
    intent.putExtra(Intent.EXTRA_TEXT, "Some random text");

    try {
        startActivity(Intent.createChooser(intent, "Send email..."));
    } catch (Exception e) {
        Toast.makeText(this, "There are no mail applications on the device!", Toast.LENGTH_LONG).show();
    }
}
Tomislav3008
  • 121
  • 9
  • This answer does not address the question about `error` or `JavaMail API`. Additionally, the question suggests not to use `Intent`. – T D Nguyen Mar 15 '15 at 21:52
  • How am I not using Intent. I make the object in the beginning and use it in the startActivity method within the try block. The chooser just gives you multiple options for applications to use the Intent object. And yes, I did not address those questions not was it my intention, I just wanted to show an example of how I made it work because no one else answered. – Tomislav3008 Apr 13 '15 at 15:34