Sample code for 30+ languages & platforms
Delphi DLL

Append MIME from a StringBuilder with Flags

See more IMAP Examples

Demonstrates the Chilkat Imap.AppendMimeWithFlagsSb method, which uploads MIME contained in a StringBuilder and sets its initial system flags. The first argument is the mailbox, the second is the StringBuilder, and the third through sixth set \Seen, \Flagged, \Answered, and \Draft. This example uploads to Drafts with the draft flag set.

Background: This is the StringBuilder form of AppendMimeWithFlags. Passing the MIME as a StringBuilder avoids copying a large message into an intermediate string and is convenient when you already built or loaded the message into a StringBuilder (for example with LoadFile).

Chilkat Delphi DLL Downloads

Delphi DLL
var
success: Boolean;
imap: HCkImap;
email: HCkEmail;
mimeText: PWideChar;
sbMime: HCkStringBuilder;
seen: Boolean;
flagged: Boolean;
answered: Boolean;
draft: Boolean;

begin
success := False;

//  Demonstrates the Imap.AppendMimeWithFlagsSb method, which uploads MIME contained in a
//  StringBuilder and sets its initial system flags.  The 1st argument is the mailbox, the 2nd
//  is the StringBuilder, and the 3rd through 6th set \Seen, \Flagged, \Answered, and \Draft.

imap := CkImap_Create();

CkImap_putSsl(imap,True);
CkImap_putPort(imap,993);

success := CkImap_Connect(imap,'imap.example.com');
if (success = False) then
  begin
    Memo1.Lines.Add(CkImap__lastErrorText(imap));
    Exit;
  end;
success := CkImap_Login(imap,'user@example.com','myPassword');
if (success = False) then
  begin
    Memo1.Lines.Add(CkImap__lastErrorText(imap));
    Exit;
  end;

//  Build the email to be uploaded.
email := CkEmail_Create();
CkEmail_putSubject(email,'Meeting agenda');
CkEmail_putFrom(email,'Alice <alice@example.com>');
success := CkEmail_AddTo(email,'Bob','bob@example.com');
CkEmail_putBody(email,'Let''s meet at 10am to review the agenda.');

mimeText := CkEmail__getMime(email);
if (CkEmail_getLastMethodSuccess(email) = False) then
  begin
    Memo1.Lines.Add(CkEmail__lastErrorText(email));
    Exit;
  end;

//  Load the MIME into a StringBuilder.  (A StringBuilder can also be filled via LoadFile.)
sbMime := CkStringBuilder_Create();
CkStringBuilder_Append(sbMime,mimeText);

//  Choose the initial flags.  Named variables make each argument's meaning clear at the call.
seen := False;
flagged := False;
answered := False;
draft := True;

//  Upload to "Drafts" with the \Draft flag set.
success := CkImap_AppendMimeWithFlagsSb(imap,'Drafts',sbMime,seen,flagged,answered,draft);
if (success = False) then
  begin
    Memo1.Lines.Add(CkImap__lastErrorText(imap));
    Exit;
  end;

Memo1.Lines.Add('Appended UID: ' + IntToStr(CkImap_getAppendUid(imap)));

success := CkImap_Disconnect(imap);
if (success = False) then
  begin
    Memo1.Lines.Add(CkImap__lastErrorText(imap));
    Exit;
  end;

CkImap_Dispose(imap);
CkEmail_Dispose(email);
CkStringBuilder_Dispose(sbMime);