Sample code for 30+ languages & platforms
Android™

Create Apple Watch HTML (text/watch-html) Email

See more Email Object Examples

Demonstrates how to create an Apple Watch text/watch-html email.

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);

    boolean success = false;

    //  This example will produce an email such as:

    //  	MIME-Version: 1.0
    //  	Date: Fri, 02 Jun 2017 09:17:06 -0500
    //  	Message-ID: <E6F1F17104442EA09740322D3E2E78806C87FB80@CHILKAT13>
    //  	X-Priority: 3 (Normal)
    //  	Subject: Apple Watch Example
    //  	From: from@example.org
    //  	To: to@example.org
    //  	Content-Type: multipart/alternative; boundary="------------080904030200000307060803"
    //  
    //  	--------------080904030200000307060803
    //  	Content-Type: text/plain; charset=utf-8
    //  	Content-Transfer-Encoding: quoted-printable
    //  	Content-Disposition: inline
    //  
    //  	This is the plain text part.
    //  	--------------080904030200000307060803
    //  	Content-Type: text/watch-html; charset=utf-8
    //  	Content-Disposition: inline
    //  	Content-Transfer-Encoding: quoted-printable
    //  
    //  	<b>This is the Watch HTML part</b>
    //  	--------------080904030200000307060803
    //  	Content-Type: text/html; charset=utf-8
    //  	Content-Disposition: inline
    //  	Content-Transfer-Encoding: quoted-printable
    //  
    //  	<p>This is the standard HTML part</p>
    //  	--------------080904030200000307060803--

    //  Create a new email instance to get the default auto-created fields.
    CkEmail email = new CkEmail();
    email.put_Body("This is the plain text part.");
    email.put_Subject("Apple Watch Example");
    email.put_From("from@example.org");
    email.AddTo("","to@example.org");

    Log.i(TAG, email.getMime());
    Log.i(TAG, "--");

    //  This is the MIME so far:
    //  (Chilkat automatically removes CKX-* headers when sending email.)

    //  	MIME-Version: 1.0
    //  	Date: Fri, 02 Jun 2017 09:17:06 -0500
    //  	Message-ID: <E6F1F17104442EA09740322D3E2E78806C87FB80@CHILKAT13>
    //  	Content-Type: text/plain; format=flowed
    //  	Content-Transfer-Encoding: 7bit
    //  	X-Priority: 3 (Normal)
    //  	Subject: Apple Watch Example
    //  	From: from@example.org
    //  	To: to@example.org
    //  
    //  	This is the plain text part.

    //  We'll use the Chilkat MIME object to build it.
    //  The MIME API provides more flexibility..
    CkMime mime = new CkMime();
    mime.LoadMime(email.getMime());

    //  Convert this MIME to multipart/alternative.
    mime.ConvertToMultipartAlt();

    Log.i(TAG, mime.getMime());
    Log.i(TAG, "--");

    //  We now have this MIME:

    //  	MIME-Version: 1.0
    //  	Date: Fri, 02 Jun 2017 09:17:06 -0500
    //  	Message-ID: <E6F1F17104442EA09740322D3E2E78806C87FB80@CHILKAT13>
    //  	X-Priority: 3 (Normal)
    //  	Subject: Apple Watch Example
    //  	From: from@example.org
    //  	To: to@example.org
    //  	Content-Type: multipart/alternative; boundary="------------080904030200000307060803"
    //  
    //  	--------------080904030200000307060803
    //  	Content-Type: text/plain; format=flowed
    //  	Content-Transfer-Encoding: 7bit
    //  
    //  	This is the plain text part.
    //  	--------------080904030200000307060803--

    //  If we desire a particular charset, encoding, or disposition..

    CkMime partPlainText = new CkMime();
    success = mime.PartAt(0,partPlainText);
    if (success == false) {
        Log.i(TAG, mime.lastErrorText());
        return;
        }

    partPlainText.put_Charset("utf-8");
    partPlainText.put_Disposition("inline");
    partPlainText.put_Encoding("quoted-printable");

    //  Create the text/watch-html MIME part and add it.
    CkMime partWatchHtml = new CkMime();
    partWatchHtml.put_ContentType("text/watch-html");
    partWatchHtml.put_Charset("utf-8");
    partWatchHtml.put_Disposition("inline");
    partWatchHtml.put_Encoding("quoted-printable");
    partWatchHtml.SetBody("<b>This is the Watch HTML part</b>");
    mime.AppendPart(partWatchHtml);

    Log.i(TAG, mime.getMime());
    Log.i(TAG, "--");

    //  We now have this MIME:

    //  	MIME-Version: 1.0
    //  	Date: Fri, 02 Jun 2017 09:17:06 -0500
    //  	Message-ID: <E6F1F17104442EA09740322D3E2E78806C87FB80@CHILKAT13>
    //  	X-Priority: 3 (Normal)
    //  	Subject: Apple Watch Example
    //  	From: from@example.org
    //  	To: to@example.org
    //  	Content-Type: multipart/alternative; boundary="------------080904030200000307060803"
    //  
    //  	--------------080904030200000307060803
    //  	Content-Type: text/plain; charset=utf-8
    //  	Content-Transfer-Encoding: quoted-printable
    //  	Content-Disposition: inline
    //  
    //  	This is the plain text part.
    //  	--------------080904030200000307060803
    //  	Content-Type: text/watch-html; charset=utf-8
    //  	Content-Disposition: inline
    //  	Content-Transfer-Encoding: quoted-printable
    //  
    //  	<b>This is the Watch HTML part</b>
    //  	--------------080904030200000307060803--

    //  Create the text/html MIME part and add it.
    CkMime partHtml = new CkMime();
    partHtml.put_ContentType("text/html");
    partHtml.put_Charset("utf-8");
    partHtml.put_Disposition("inline");
    partHtml.put_Encoding("quoted-printable");
    partHtml.SetBody("<p>This is the standard HTML part</p>");
    mime.AppendPart(partHtml);

    Log.i(TAG, mime.getMime());
    Log.i(TAG, "--");

    //  We now have this MIME:

    //  	MIME-Version: 1.0
    //  	Date: Fri, 02 Jun 2017 09:17:06 -0500
    //  	Message-ID: <E6F1F17104442EA09740322D3E2E78806C87FB80@CHILKAT13>
    //  	X-Priority: 3 (Normal)
    //  	Subject: Apple Watch Example
    //  	From: from@example.org
    //  	To: to@example.org
    //  	Content-Type: multipart/alternative; boundary="------------080904030200000307060803"
    //  
    //  	--------------080904030200000307060803
    //  	Content-Type: text/plain; charset=utf-8
    //  	Content-Transfer-Encoding: quoted-printable
    //  	Content-Disposition: inline
    //  
    //  	This is the plain text part.
    //  	--------------080904030200000307060803
    //  	Content-Type: text/watch-html; charset=utf-8
    //  	Content-Disposition: inline
    //  	Content-Transfer-Encoding: quoted-printable
    //  
    //  	<b>This is the Watch HTML part</b>
    //  	--------------080904030200000307060803
    //  	Content-Type: text/html; charset=utf-8
    //  	Content-Disposition: inline
    //  	Content-Transfer-Encoding: quoted-printable
    //  
    //  	<p>This is the standard HTML part</p>
    //  	--------------080904030200000307060803--

    //  Load the email object with this MIME, and we're good to go..
    email.SetFromMimeText(mime.getMime());
    Log.i(TAG, email.getMime());

  }

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