PureBasic
PureBasic
Change the Filename of a Related Item
See more Email Object Examples
Demonstrates the Chilkat Email.SetRelatedFilename method, which sets (changes) the filename stored for a related item within the email. The index is zero-based. This example adds a related style sheet and renames it, printing the filename before and after.
Background: A related item's filename identifies the embedded resource within the message. Changing it is occasionally needed to match how the HTML body references the resource, or to give an embedded image or style sheet a cleaner name. Keep in mind that if the HTML links to the item by that name (via
Content-Location), the reference should be kept in sync with the new filename.Chilkat PureBasic Downloads
IncludeFile "CkEmail.pb"
Procedure ChilkatExample()
success.i = 0
; Demonstrates the SetRelatedFilename method, which sets (changes) the filename of a
; related item within the email. The index is zero-based.
email.i = CkEmail::ckCreate()
If email.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkEmail::setCkSubject(email, "Set related item filename")
; Set an HTML body and add a related style sheet (index 0).
CkEmail::ckSetHtmlBody(email,"<html><head><link rel=" + Chr(34) + "stylesheet" + Chr(34) + " href=" + Chr(34) + "styles.css" + Chr(34) + "/></head><body>Styled.</body></html>")
CkEmail::ckAddRelatedString2(email,"styles.css","body { color: navy; }","utf-8")
Debug "Related filename before: " + CkEmail::ckGetRelatedFilename(email,0)
; Change the filename of the related item at index 0.
success = CkEmail::ckSetRelatedFilename(email,0,"main.css")
If success = 0
Debug CkEmail::ckLastErrorText(email)
CkEmail::ckDispose(email)
ProcedureReturn
EndIf
Debug "Related filename after: " + CkEmail::ckGetRelatedFilename(email,0)
CkEmail::ckDispose(email)
ProcedureReturn
EndProcedure