PowerBuilder
PowerBuilder
Get the Content-Type of Each Alternative Body
See more Email Object Examples
Demonstrates the Chilkat Email.GetAlternativeContentType method, which returns the content type of the Nth alternative body. The NumAlternatives property gives the number of alternatives, and indexes are zero-based. This example builds a message with plain-text and HTML alternatives and prints the content type of each.
Background: Each alternative in a
multipart/alternative message declares a Content-Type such as text/plain or text/html. Enumerating those types tells you which representations a message actually contains before you fetch a body — letting you decide, for instance, whether an HTML version exists or whether you must fall back to plain text. It is the natural companion to GetAlternativeBody, which fetches the body at the same index.Chilkat PowerBuilder Downloads
integer li_rc
oleobject loo_Email
integer n
integer i
// Demonstrates the GetAlternativeContentType method, which returns the content type of
// the Nth alternative body. The NumAlternatives property gives the number of
// alternatives; indexes are zero-based.
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
// Create an email with plain-text and HTML alternatives.
loo_Email.SetTextBody("This is the plain-text alternative.","text/plain")
loo_Email.AddHtmlAlternativeBody("<html><body>This is the HTML alternative.</body></html>")
n = loo_Email.NumAlternatives
for i = 0 to n - 1
Write-Debug "Alternative " + string(i) + " content type: " + loo_Email.GetAlternativeContentType(i)
next
destroy loo_Email