PureBasic
PureBasic
Set the Charset of an Attachment
See more Email Object Examples
Demonstrates the Chilkat Email.SetAttachmentCharset method, which sets the charset parameter of the Content-Type header field for the attachment at a given zero-based index. This example adds a text attachment and sets its charset to utf-8.
Background: For a text attachment, the
charset parameter tells the receiving client which character encoding the bytes use, so accented or non-Latin text renders correctly. Setting it explicitly (typically utf-8) removes ambiguity when the attachment contains non-ASCII content — without it, a client may guess wrong and display garbled characters.Chilkat PureBasic Downloads
IncludeFile "CkEmail.pb"
Procedure ChilkatExample()
success.i = 0
; Demonstrates the SetAttachmentCharset method, which sets the charset parameter of the
; Content-Type header field for the attachment at the given zero-based index.
email.i = CkEmail::ckCreate()
If email.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkEmail::setCkSubject(email, "Set attachment charset")
CkEmail::ckAddStringAttachment(email,"notes.txt","Some notes.")
; Set the charset of the first attachment (index 0) to utf-8.
success = CkEmail::ckSetAttachmentCharset(email,0,"utf-8")
If success = 0
Debug CkEmail::ckLastErrorText(email)
CkEmail::ckDispose(email)
ProcedureReturn
EndIf
; The attachment's Content-Type now includes charset="utf-8".
Debug CkEmail::ckGetMime(email)
CkEmail::ckDispose(email)
ProcedureReturn
EndProcedure