android送信メールコード

1658 ワード

 Button bt5 = (Button) findViewById(R.id.Button05);

        bt5.setOnClickListener(new OnClickListener() {

                @Override

                public void onClick(View v) {

                        // Setup the recipient in a String array

                        String[] mailto = { "[email protected]" };

                        // Create a new Intent to send messages

                        Intent sendIntent = new Intent(Intent.ACTION_SEND);

                        // Write the body of theEmail

                        String emailBody = "You're password is: ";

                        // Add attributes to the intent

//                        sendIntent.setType("text/plain"); // use this line for testing

                                                                                                // in the emulator

                        sendIntent.setType("message/rfc822"); // use this line for testing 

                                                                                                        // on the real phone

                        sendIntent.putExtra(Intent.EXTRA_EMAIL, mailto);

                        sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Your Password");

                        sendIntent.putExtra(Intent.EXTRA_TEXT, emailBody);

                        startActivity(sendIntent);

                }

        });