Ishara Madushani
Ishara Madushani

Reputation: 41

sending Email in Android

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

Upvotes: 3

Views: 113

Answers (1)

Tomislav3008
Tomislav3008

Reputation: 121

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();
    }
}

Upvotes: 2

Related Questions