Sample code for 30+ languages & platforms
VBScript

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 VBScript Downloads

VBScript
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)

success = 0

'  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.

set imap = CreateObject("Chilkat.Imap")

imap.Ssl = 1
imap.Port = 993

success = imap.Connect("imap.example.com")
If (success = 0) Then
    outFile.WriteLine(imap.LastErrorText)
    WScript.Quit
End If

success = imap.Login("user@example.com","myPassword")
If (success = 0) Then
    outFile.WriteLine(imap.LastErrorText)
    WScript.Quit
End If

'  Build the email to be uploaded.
set email = CreateObject("Chilkat.Email")
email.Subject = "Meeting agenda"
email.From = "Alice <alice@example.com>"
success = email.AddTo("Bob","bob@example.com")
email.Body = "Let's meet at 10am to review the agenda."

mimeText = email.GetMime()
If (email.LastMethodSuccess = 0) Then
    outFile.WriteLine(email.LastErrorText)
    WScript.Quit
End If

'  Load the MIME into a StringBuilder.  (A StringBuilder can also be filled via LoadFile.)
set sbMime = CreateObject("Chilkat.StringBuilder")
success = sbMime.Append(mimeText)

'  Choose the initial flags.  Named variables make each argument's meaning clear at the call.
seen = 0
flagged = 0
answered = 0
draft = 1

'  Upload to "Drafts" with the \Draft flag set.
success = imap.AppendMimeWithFlagsSb("Drafts",sbMime,seen,flagged,answered,draft)
If (success = 0) Then
    outFile.WriteLine(imap.LastErrorText)
    WScript.Quit
End If

outFile.WriteLine("Appended UID: " & imap.AppendUid)

success = imap.Disconnect()
If (success = 0) Then
    outFile.WriteLine(imap.LastErrorText)
    WScript.Quit
End If


outFile.Close