Home > Net >  How can I identify the recipient of the email?
How can I identify the recipient of the email?

Time:04-17

//Intent to gmail        
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.setData(Uri.parse("mailto:"));
//how can ı add this part
sendIntent.putExtra(Intent.EXTRA_EMAIL,fromEmail);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Feedback");
sendIntent.putExtra(Intent.EXTRA_TEXT, emailBody);
sendIntent.setType("text/plain");
try {
    Intent shareIntent = Intent.createChooser(sendIntent, "Feedback");
    startActivity(shareIntent);
    Log.i("Finished sending email...", "");
} catch (android.content.ActivityNotFoundException ex) {
    Toast.makeText(MainActivity.this, "There is no email client installed.", Toast.LENGTH_SHORT).show();
}

The sender works fine, but I couldn't make the receiver. Can you help me?

CodePudding user response:

I don't know exactly how the design is. I'm also not sure where you got the recipient email from, but maybe this code will be useful for you.

public void contact() {
    final Intent send = new Intent(Intent.ACTION_SENDTO);

    final String email = "[email protected]";
    final String subject = "subject";
    final String body = "body...";

    final String uriText = "mailto:"   Uri.encode(email)  
            "?subject="   Uri.encode(subject)  
            "&body="   Uri.encode(body);
    final Uri uri = Uri.parse(uriText);

    send.setData(uri);
    startActivity(Intent.createChooser(send, getString(R.string.settings_email_chooser)));
}
  • Related