Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How to confirm that email has been sent successfully

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.

like image 357
android_guy Avatar asked Nov 12 '22 18:11

android_guy


1 Answers

You cannot do this using : android.content.Intent.ACTION_SEND. Just try to send a mail using the mailing app to a email ID that doesnot exist. You will see that the app does not notify you of the failed delivery. Using android.content.Intent.ACTION_SEND, you are actually passing an intent to the same app to do the email delivery task for you. So you will never know if your mail delivery has failed.

The work around. You need to implement the email delivery a 3rd party Library mail.jar or some thing similar. But the thing is you need to have senders' mailID and PASSWORD both to set this up. May be you can have a dummy email account with which you can send the mail.

This can help.

like image 72
Parth Kapoor Avatar answered Nov 15 '22 04:11

Parth Kapoor