Android™
Android™
Check if an Email Was Received Encrypted
See more Email Object Examples
Demonstrates the read-only Chilkat Email.ReceivedEncrypted property, which is true if the email was originally received with encryption. This records how the message arrived and remains useful even after successful automatic decryption, when the visible body is already the decrypted content. This example loads an email and reports whether it was received encrypted.
Background: When Chilkat loads an encrypted (S/MIME) email and has the recipient's private key available, it decrypts the content automatically — so the body you read is already in the clear. That convenience creates a question: was this message originally protected in transit?
ReceivedEncrypted answers it, letting you distinguish a message that was genuinely encrypted end-to-end from one that was sent as plain text. Pair it with Decrypted to confirm decryption actually succeeded.Chilkat Android™ Downloads
// 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 {
private static final String TAG = "Chilkat";
// Called when the activity is first created.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
boolean success = false;
// Demonstrates the read-only Email.ReceivedEncrypted property, which is true if
// this email was originally received with encryption. It remains meaningful even
// after Chilkat automatically decrypts the message.
CkEmail email = new CkEmail();
success = email.LoadEml("qa_data/eml/received.eml");
if (success == false) {
Log.i(TAG, email.lastErrorText());
return true;
}
if (email.get_ReceivedEncrypted() == true) {
Log.i(TAG, "This email was originally received encrypted.");
}
else {
Log.i(TAG, "This email was not received encrypted.");
}
// Note: Paths such as "qa_data/..." are relative local filesystem paths,
// relative to the current working directory of the running application.
}
static {
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."
}
}