DataFlex
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoEmail
Variant vDomains
Handle hoDomains
Integer n
Integer i
String sTemp1
Move False To iSuccess
// 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.
Get Create (RefClass(cComChilkatEmail)) To hoEmail
If (Not(IsComObjectCreated(hoEmail))) Begin
Send CreateComObject of hoEmail
End
Set ComSubject Of hoEmail To "LinkedDomains example"
// An HTML body containing several hyperlinks.
Send ComSetHtmlBody To hoEmail '<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.
Get Create (RefClass(cComChilkatStringTable)) To hoDomains
If (Not(IsComObjectCreated(hoDomains))) Begin
Send CreateComObject of hoDomains
End
Get pvComObject of hoDomains to vDomains
Get ComLinkedDomains Of hoEmail vDomains To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoEmail To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComCount Of hoDomains To n
For i From 0 To (n - 1)
Get ComStringAt Of hoDomains i To sTemp1
Showln sTemp1
Loop
End_Procedure