Here is my code that is able to sent email successfully
package com.send.email;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity {
Button send;
EditText address, subject, emailtext;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
send = (Button) findViewById(R.id.emailsendbutton);
address = (EditText) findViewById(R.id.emailaddress);
subject = (EditText) findViewById(R.id.emailsubject);
emailtext = (EditText) findViewById(R.id.emailtext);
send.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("image/png");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { address.getText().toString() });
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject.getText());
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailtext.getText());
MainActivity.this.startActivity(Intent.createChooser(emailIntent,"Send mail..."));
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if(requestCode==1)
{
if(requestCode==1 && resultCode==Activity.RESULT_OK)
{
Toast.makeText(this, "Mail sent.", Toast.LENGTH_SHORT).show();
}
else if (requestCode==1 && resultCode==Activity.RESULT_CANCELED)
{
Toast.makeText(this, "Mail canceled.", Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(this, "Plz try again.", Toast.LENGTH_SHORT).show();
}
}
}
}
I want to get some information back to check whether the email has been sent successfully or not. It always prints the message "send email" and opens built-in email client and sends email.