(Chilkat for Android™ API) Getting TO / CC Email Recipients
Demonstrates how to examine the TO and CC recipients of an email.
Note: BCC recipients are generally NOT found in the email's MIME. "BCC" is a "Blind Carbon Copy", which means that the TO and CC recipients of the email should not be able to see the BCC recipients. If the BCC email addresses were found in the MIME header, then they would no longer be "blind" because nothing would prevent the other recipients from seeing the list of BCC recipients.
To understand how BCC recipients receive an email, I recommend reading this blog post: SMTP Protocol in a Nutshell. The BCC recipients are passed to the SMTP server in “RCPT TO” commands.
Download: Chilkat for Android™ Java Libraries
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;
import android.app.Activity;
import com.chilkatsoft.*;
import android.widget.TextView;
import android.os.Bundle;
public class SimpleActivity extends Activity {
// Called when the activity is first created.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
String outStr = "";
// An email can have any number of To, CC, or Bcc recipients.
CkEmail email = new CkEmail();
boolean success;
success = email.LoadEml("sample.eml");
if (success != true) {
outStr += email.lastErrorText() + "\n";
tv.setText(outStr);
setContentView(tv);
return;
}
// It doesn't matter if the email object was loaded from a .eml file,
// or if it was downloaded from a POP3 or IMAP server.
// The methods and properties for examining the TO and CC
// recipients are the same.
int i;
// The number of TO recipients is found in the NumTo property
int numTo;
numTo = email.get_NumTo();
// Iterate over each TO recipient
if (numTo > 0) {
for (i = 0; i <= numTo - 1; i++) {
outStr += "TO Friendly Name and Address: "
+ email.getTo(i) + "\n";
outStr += "TO Address: " + email.getToAddr(i) + "\n";
outStr += "TO Friendly Name: " + email.getToName(i) + "\n";
outStr += "---" + "\n";
}
}
// The number of CC recipients is found in the NumCC property
int numCC;
numCC = email.get_NumCC();
// Iterate over each CC recipient
if (numCC > 0) {
for (i = 0; i <= numCC - 1; i++) {
outStr += "CC Friendly Name and Address: "
+ email.getCC(i) + "\n";
outStr += "CC Address: " + email.getCcAddr(i) + "\n";
outStr += "CC Friendly Name: " + email.getCcName(i) + "\n";
outStr += "---" + "\n";
}
}
tv.setText(outStr);
setContentView(tv);
}
static {
// Important: Make sure the name passed to loadLibrary matches the shared library
// found in your project's libs/armeabi directory.
// for "libchilkat.so", pass "chilkat" to loadLibrary
// for "libchilkatemail.so", pass "chilkatemail" to loadLibrary
// etc.
//
System.loadLibrary("chilkat");
// Note: If the incorrect library name is passed to System.loadLibrary,
// then you will see the following error message at application startup:
//"The application <your-application-name> has stopped unexpectedly. Please try again."
}
}
|