Sample code for 30+ languages & platforms
PowerBuilder

Add a MIME Header Field

See more MIME Examples

Demonstrates the Chilkat Mime.AddHeaderField method, which appends a new header field. The first argument is the field name and the second is the value. Existing fields with the same case-insensitive name are preserved, so this can create duplicates.

Background: MIME headers are ordered name/value lines, and some — Received, for instance — legitimately appear more than once. AddHeaderField is the tool for that: it always appends, never replacing an existing field of the same name. When you instead want exactly one field with a given name, use SetHeaderField, which replaces rather than accumulates.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
long li_Success
oleobject loo_Mime
string ls_Headers

li_Success = 0

//  Demonstrates the Mime.AddHeaderField method, which appends a new header field.  The 1st argument
//  is the field name and the 2nd is the value.  Existing fields with the same (case-insensitive)
//  name are preserved, so this can create duplicate fields.

loo_Mime = create oleobject
li_rc = loo_Mime.ConnectToNewObject("Chilkat.Mime")
if li_rc < 0 then
    destroy loo_Mime
    MessageBox("Error","Connecting to COM object failed")
    return
end if

li_Success = loo_Mime.SetBodyFromPlainText("Hello.")
if li_Success = 0 then
    Write-Debug loo_Mime.LastErrorText
    destroy loo_Mime
    return
end if

//  Append header fields.  AddHeaderField does not replace existing fields of the same name.
li_Success = loo_Mime.AddHeaderField("X-Custom-Header","value1")
if li_Success = 0 then
    Write-Debug loo_Mime.LastErrorText
    destroy loo_Mime
    return
end if

li_Success = loo_Mime.AddHeaderField("X-Priority","3")
if li_Success = 0 then
    Write-Debug loo_Mime.LastErrorText
    destroy loo_Mime
    return
end if

ls_Headers = loo_Mime.GetEntireHead()
if loo_Mime.LastMethodSuccess = 0 then
    Write-Debug loo_Mime.LastErrorText
    destroy loo_Mime
    return
end if

Write-Debug ls_Headers


destroy loo_Mime