2

hello i am trying to send an email from an android application , the below code is working fine since it is opening the email app configured on the phone but the problem is it is not taking the subject and the Bcc any ideas

send.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub

        final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
        emailIntent.setType("plain/text");
        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, emailBody.getText());
        emailIntent.putExtra(android.content.Intent.EXTRA_BCC, CC.getText());
        startActivity(Intent.createChooser(emailIntent, "Send mail..."));
    }
});
Chintan Rathod
  • 25,864
  • 13
  • 83
  • 93

3 Answers3

1

Try

send.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
        emailIntent.setType("plain/text");
        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{ address.getText().toString()});
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject.getText().toString());
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailBody.getText().toString());
        emailIntent.putExtra(android.content.Intent.EXTRA_BCC, CC.getText().toString());
        startActivity(Intent.createChooser(emailIntent, "Send mail..."));
    }
});

EditText.getText() return a editable you need to change it to String by applying toString();

Chintan Rathod
  • 25,864
  • 13
  • 83
  • 93
Rajnish Mishra
  • 826
  • 5
  • 21
1

As you can see in the getting the address you got the text by .getText(); then you made it a string for other uses, because it was an editable text from editText. But in the other EditTextss you forgot to add .toString(); so you can use it as a string in email.

try this:

send.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {

        final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
        emailIntent.setType("plain/text");

        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{ address.getText().toString()});
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject.getText().toString());
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailBody.getText().toString());
        emailIntent.putExtra(android.content.Intent.EXTRA_BCC, CC.getText().toString());

        startActivity(Intent.createChooser(emailIntent, "Send mail..."));
    }
});

please ask if you didn't understand

Chintan Rathod
  • 25,864
  • 13
  • 83
  • 93
Ahmed Ekri
  • 4,601
  • 3
  • 23
  • 42
0

Will work 100%

String[] to = value.toString().split(",");
        Intent i = new Intent(Intent.ACTION_SEND);
        i.setType("text/html");
        i.putExtra(Intent.EXTRA_EMAIL, to);
        i.putExtra(Intent.EXTRA_BCC, "array of bcc like to");
        i.putExtra(Intent.EXTRA_SUBJECT, String.format(getString(R.string.share_email_subject), IN_SHARE_CAPTION));
        i.putExtra(
                Intent.EXTRA_TEXT,
                Html.fromHtml(IjoomerUtilities.prepareEmailBody(message == null ? "" : message, getSmartApplication().readSharedPreferences().getString(SP_USERNAME, "") + " " + getString(R.string.saw_this_story_on_the) + " "
                        + getString(R.string.app_name) + " " + getString(R.string.thought_you_should_see_it), IN_SHARE_CAPTION, IN_SHARE_DESCRIPTION, IN_SHARE_SHARELINK, getString(R.string.try_ijoomeradvance), getString(R.string.site_url))));
        try {
            startActivity(Intent.createChooser(i, "Send mail..."));
            finish();
        } catch (android.content.ActivityNotFoundException ex) {
            ting(getString(R.string.share_email_no_client));
        }
Biraj Zalavadia
  • 28,348
  • 10
  • 61
  • 77