Android™
Android™
Extract Linked Domains from an HTML Email
See more Email Object Examples
Demonstrates the Chilkat Email.LinkedDomains method, which extracts the domain names from the hyperlinks in an HTML email. Lowercase domains are appended to a StringTable without creating duplicates. This example sets an HTML body with several links and lists the distinct domains.
Background: The set of domains a message links to is a strong signal for spam and phishing analysis — legitimate mail usually points at a few expected domains, while abusive mail often hides links to many unrelated or look-alike hosts.
LinkedDomains gives you that de-duplicated list directly. Note it only parses the links; it does not fetch them, so no network request is made.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 LinkedDomains method, which extracts the domain names from the
// hyperlinks in an HTML email. Lowercase domains are appended to a StringTable without
// creating duplicates.
CkEmail email = new CkEmail();
email.put_Subject("LinkedDomains example");
// An HTML body containing several hyperlinks.
email.SetHtmlBody("<html><body>Visit <a href=\"https://www.example.com/page\">Example</a>, <a href=\"http://sales.contoso.com\">Contoso</a>, and <a href=\"https://www.example.com/other\">Example again</a>.</body></html>");
// Extract the linked domains into a StringTable.
CkStringTable domains = new CkStringTable();
success = email.LinkedDomains(domains);
if (success == false) {
Log.i(TAG, email.lastErrorText());
return true;
}
int n = domains.get_Count();
int i;
for (i = 0; i <= n - 1; i++) {
Log.i(TAG, domains.stringAt(i));
}
}
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."
}
}