Sample code for 30+ languages & platforms
PowerBuilder

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 PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Email
oleobject loo_Domains
integer n
integer i

li_Success = 0

//  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.

loo_Email = create oleobject
li_rc = loo_Email.ConnectToNewObject("Chilkat.Email")
if li_rc < 0 then
    destroy loo_Email
    MessageBox("Error","Connecting to COM object failed")
    return
end if
loo_Email.Subject = "LinkedDomains example"

//  An HTML body containing several hyperlinks.
loo_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.
loo_Domains = create oleobject
li_rc = loo_Domains.ConnectToNewObject("Chilkat.StringTable")

li_Success = loo_Email.LinkedDomains(loo_Domains)
if li_Success = 0 then
    Write-Debug loo_Email.LastErrorText
    destroy loo_Email
    destroy loo_Domains
    return
end if

n = loo_Domains.Count

for i = 0 to n - 1
    Write-Debug loo_Domains.StringAt(i)
next


destroy loo_Email
destroy loo_Domains