PowerBuilder
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Imap
oleobject loo_Email
string ls_MimeText
oleobject loo_SbMime
integer li_Seen
integer li_Flagged
integer li_Answered
integer li_Draft
li_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.
loo_Imap = create oleobject
li_rc = loo_Imap.ConnectToNewObject("Chilkat.Imap")
if li_rc < 0 then
destroy loo_Imap
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_Imap.Ssl = 1
loo_Imap.Port = 993
li_Success = loo_Imap.Connect("imap.example.com")
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
return
end if
li_Success = loo_Imap.Login("user@example.com","myPassword")
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
return
end if
// Build the email to be uploaded.
loo_Email = create oleobject
li_rc = loo_Email.ConnectToNewObject("Chilkat.Email")
loo_Email.Subject = "Meeting agenda"
loo_Email.From = "Alice <alice@example.com>"
li_Success = loo_Email.AddTo("Bob","bob@example.com")
loo_Email.Body = "Let's meet at 10am to review the agenda."
ls_MimeText = loo_Email.GetMime()
if loo_Email.LastMethodSuccess = 0 then
Write-Debug loo_Email.LastErrorText
destroy loo_Imap
destroy loo_Email
return
end if
// Load the MIME into a StringBuilder. (A StringBuilder can also be filled via LoadFile.)
loo_SbMime = create oleobject
li_rc = loo_SbMime.ConnectToNewObject("Chilkat.StringBuilder")
loo_SbMime.Append(ls_MimeText)
// Choose the initial flags. Named variables make each argument's meaning clear at the call.
li_Seen = 0
li_Flagged = 0
li_Answered = 0
li_Draft = 1
// Upload to "Drafts" with the \Draft flag set.
li_Success = loo_Imap.AppendMimeWithFlagsSb("Drafts",loo_SbMime,li_Seen,li_Flagged,li_Answered,li_Draft)
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
destroy loo_Email
destroy loo_SbMime
return
end if
Write-Debug "Appended UID: " + string(loo_Imap.AppendUid)
li_Success = loo_Imap.Disconnect()
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
destroy loo_Email
destroy loo_SbMime
return
end if
destroy loo_Imap
destroy loo_Email
destroy loo_SbMime