Sample code for 30+ languages & platforms
Android™

Get the Size of an Email in Bytes

See more Email Object Examples

Demonstrates the read-only Chilkat Email.Size property, which is the size in bytes of the email, including all parts and attachments. This value describes the email data currently present in the object. Important: it is only valid when the full email was downloaded — if only the header was retrieved, Size reflects just the header, so do not treat it as the server-reported full message size after a partial download. This example builds an email with an attachment and prints its size.

Background: An email's on-the-wire size is usually larger than the raw content it carries. Attachments and other binary parts are encoded as text (typically Base64) so they survive mail transport, and Base64 inflates data by roughly 33%. Add MIME headers and boundary markers for each part, and the byte count reported by Size reflects this fully-assembled message — which is what actually counts against mailbox quotas and server size limits.

Chilkat Android™ Downloads

Android™
// 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);

    //  Demonstrates the read-only Email.Size property, which is the size in bytes of the
    //  email including all parts and attachments.  Note: it is only valid when the full email
    //  is present; if only the header was downloaded, it reflects just the header size.

    CkEmail email = new CkEmail();
    email.put_Subject("Size example");
    email.put_Body("This is the body of the email.");
    email.AddStringAttachment("data.txt","Some attached content.");

    Log.i(TAG, "Size (bytes) = " + String.valueOf(email.get_Size()));

  }

  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."
  }
}