Jump to content
bzwirs

Send Email from Android with multiple CC addresses

Recommended Posts

Latest Delphi

Trying to send email from Android that is always sent to one address but can have up to 3 CC addresses......the send to address shows up ok in the email but not any of the CC addresses. The code I use is shown below.

 

Intent := TJIntent.JavaClass.init(TJIntent.JavaClass.ACTION_SEND);

  sRecipients := TJavaObjectArray<JString>.Create(1);
  sRecipients.Items[0] := StringToJString(Recipient);

  ccRecipient := TJavaObjectArray<JString>.Create(1);
  ccRecipient.Items[0] := StringToJString(ccTechs);

  Intent.putExtra(TJIntent.JavaClass.EXTRA_EMAIL,sRecipients);
  Intent.putExtra(TJIntent.JavaClass.EXTRA_CC, ccRecipient);
  Intent.putExtra(TJIntent.JavaClass.EXTRA_SUBJECT, StringToJString(aSubject));
  Intent.putExtra(TJIntent.JavaClass.EXTRA_TEXT, StringToJString(aBody));
  Intent.setType(StringToJString('plain/text'));
  TAndroidHelper.Activity.startActivity(TJIntent.JavaClass.createChooser(Intent,
                                        StrToJCharSequence('Which email app?')));

The ccTechs variable is a string of addresses - each address separated by a comma.

All works fine except the ccRecipient is always missing.  

 

Can someone please explain what I am doing wrong.

 

Thanks in advance

 

Bill Zwirs

 

Share this post


Link to post
13 hours ago, bzwirs said:

The ccTechs variable is a string of addresses - each address separated by a comma.

EXTRA_CC takes a String[] array as input.  You are creating a 1-element array holding a comma-delimited string.  Try separating out the individual addresses instead, one address per array element.  You could use Java's String.split() method for that, eg:

Intent.putExtra(TJIntent.JavaClass.EXTRA_CC,
  StringToJString(Trim(ccTechs)).split(StringToJString('\s*,\s*'))
);

Also, whether or not the email will populate the CC field is up to the email app that processes the Intent, it is not up to your code.  It is possible that the email app you are testing with simply ignores the EXTRA_CC data.  For example, Gmail 4.2 suffered from this problem, but that was fixed in Gmail 4.3.

Edited by Remy Lebeau

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×