Sample code for 30+ languages & platforms
Delphi DLL

Serialize MIME to a StringBuilder

See more MIME Examples

Demonstrates the Chilkat Mime.GetMimeSb method, which serializes the complete MIME entity and appends it to a StringBuilder. The only argument is the StringBuilder; existing content is preserved.

Background: Serializing into a StringBuilder avoids creating a new string and is convenient when you are accumulating output or building a larger document. Because it appends, you can assemble several pieces in one buffer. As with GetMime, use the BinData form for content with arbitrary binary bytes.

Chilkat Delphi DLL Downloads

Delphi DLL
var
success: Boolean;
mime: HCkMime;
sb: HCkStringBuilder;

begin
success := False;

//  Demonstrates the Mime.GetMimeSb method, which serializes the complete MIME entity and appends
//  it to a StringBuilder.  The only argument is the StringBuilder.

mime := CkMime_Create();

success := CkMime_SetBodyFromPlainText(mime,'Hello, this is the message body.');
if (success = False) then
  begin
    Memo1.Lines.Add(CkMime__lastErrorText(mime));
    Exit;
  end;

//  Append the serialized MIME to a StringBuilder.  Existing content is preserved.
sb := CkStringBuilder_Create();
success := CkMime_GetMimeSb(mime,sb);
if (success = False) then
  begin
    Memo1.Lines.Add(CkMime__lastErrorText(mime));
    Exit;
  end;

Memo1.Lines.Add(CkStringBuilder__getAsString(sb));

CkMime_Dispose(mime);
CkStringBuilder_Dispose(sb);