Sample code for 30+ languages & platforms
CkJava Requires Chilkat v11.0.0+

Put a web link in an HTML email

See more Email Object Examples

An ordinary hyperlink belongs in the HTML body. It needs no related MIME part. Provide the URL in the text alternative for readers that display plain text.

Chilkat CkJava Downloads

CkJava
import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    boolean success = false;

    //  Assumes Chilkat is unlocked. See Global Unlock Sample.

    CkEmail email = new CkEmail();
    email.put_From("Workshop team <events@example.com>");
    success = email.AddTo("Alex Rivera","alex@example.net");
    if (success != true) {
        System.out.println(email.lastErrorText());
        return;
        }

    email.put_Subject("Workshop directions");
    //  Use an absolute URL because the message has no website base URL.
    success = email.AddPlainTextAlternativeBody("Directions: https://example.com/workshop/map");
    if (success != true) {
        System.out.println(email.lastErrorText());
        return;
        }

    success = email.AddHtmlAlternativeBody("<p><a href='https://example.com/workshop/map'>View workshop directions</a></p>");
    if (success != true) {
        System.out.println(email.lastErrorText());
        return;
        }

    success = email.SaveEml("directions.eml");
    if (success != true) {
        System.out.println(email.lastErrorText());
        return;
        }

    System.out.println("Saved directions.eml.");
  }
}