Sample code for 30+ languages & platforms
Visual Basic 6.0

Append MIME with Initial IMAP Flags

See more IMAP Examples

Demonstrates the Chilkat Imap.AppendMimeWithFlags method, which uploads a MIME message and sets its initial system flags. The first argument is the mailbox and the second is the MIME text. The third through sixth arguments control \Seen, \Flagged, \Answered, and \Draft respectively — pass true to set a flag. This example uploads a message that is already marked read.

Background: When importing or archiving mail you frequently want the uploaded message to arrive in a particular state — already read, pre-flagged, or marked as a draft. Setting the flags at append time is a single operation, avoiding a second STORE round trip. These explicit arguments take precedence over the AppendSeen property.

Chilkat Visual Basic 6.0 Downloads

Visual Basic 6.0
Dim success As Long
success = 0

'  Demonstrates the Imap.AppendMimeWithFlags method, which uploads a MIME message and sets its
'  initial system flags.  The 1st argument is the mailbox, the 2nd is the MIME text, and the
'  3rd through 6th arguments set the \Seen, \Flagged, \Answered, and \Draft flags.

Dim imap As New ChilkatImap

imap.Ssl = 1
imap.Port = 993

success = imap.Connect("imap.example.com")
If (success = 0) Then
    Debug.Print imap.LastErrorText
    Exit Sub
End If

success = imap.Login("user@example.com","myPassword")
If (success = 0) Then
    Debug.Print imap.LastErrorText
    Exit Sub
End If

'  Build the email to be uploaded.
Dim email As New ChilkatEmail
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."

Dim mimeText As String
mimeText = email.GetMime()
If (email.LastMethodSuccess = 0) Then
    Debug.Print email.LastErrorText
    Exit Sub
End If

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

'  Upload to the Inbox already marked as read (\Seen), with the other flags unset.
success = imap.AppendMimeWithFlags("Inbox",mimeText,seen,flagged,answered,draft)
If (success = 0) Then
    Debug.Print imap.LastErrorText
    Exit Sub
End If

Debug.Print "Appended UID: " & imap.AppendUid

success = imap.Disconnect()
If (success = 0) Then
    Debug.Print imap.LastErrorText
    Exit Sub
End If