PowerBuilder
PowerBuilder
Add a Custom Header to a Related Item
See more Email Object Examples
Demonstrates the Chilkat Email.AddRelatedHeader method, which adds a custom MIME header field to an existing related item identified by its zero-based index. This example first adds a related style sheet (which becomes index 0) and captures its generated Content-ID, builds an HTML body that references the style sheet by that cid:, then attaches an extra header field to the related item and prints the resulting MIME.
Background: Like attachments, each related item (an inline image, style sheet, etc.) is a MIME part with its own small header block describing that part —
Content-Type, Content-ID, Content-Location, and so on. AddRelatedHeader lets you insert additional fields into that per-part block, which is occasionally required for interoperability with clients that look for specific custom headers on embedded resources.Chilkat PowerBuilder Downloads
integer li_rc
oleobject loo_Email
string ls_Cid
oleobject loo_SbHtml
integer li_NumReplaced
// Demonstrates the AddRelatedHeader method, which adds a custom MIME header field to an
// existing related item, identified by its zero-based index.
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 = "Related item with a custom header"
// Add a related item first (a style sheet); capture its generated Content-ID. It becomes
// related-item index 0.
ls_Cid = loo_Email.AddRelatedString("styles.css","body { color: black; }","utf-8")
if loo_Email.LastMethodSuccess = 0 then
Write-Debug loo_Email.LastErrorText
destroy loo_Email
return
end if
// Build the HTML body, referencing the related style sheet by its Content-ID. A
// placeholder is used and then replaced with the actual Content-ID.
loo_SbHtml = create oleobject
li_rc = loo_SbHtml.ConnectToNewObject("Chilkat.StringBuilder")
loo_SbHtml.Append("<html><head><link rel=~"stylesheet~" href=~"cid:PLACEHOLDER_CID~"/></head><body>Styled content.</body></html>")
li_NumReplaced = loo_SbHtml.Replace("PLACEHOLDER_CID",ls_Cid)
loo_Email.SetHtmlBody(loo_SbHtml.GetAsString())
// Add a custom header field to the first related item (index 0).
loo_Email.AddRelatedHeader(0,"X-Custom-Related-Header","some value")
// The custom header now appears in the related item's MIME part.
Write-Debug loo_Email.GetMime()
destroy loo_Email
destroy loo_SbHtml