Sample code for 30+ languages & platforms
PowerBuilder

Append a MIME Message to an IMAP Mailbox

See more IMAP Examples

Demonstrates the Chilkat Imap.AppendMime method, which uploads a complete RFC 822/MIME message to a mailbox. The first argument is the destination mailbox name and the second is the MIME text. This example obtains the MIME from an Email object and uploads it to Drafts.

Background: Use AppendMime when you already hold a message's raw source — a .eml file, a message you assembled, or one you received. Chilkat sends the text exactly as supplied, without normalizing line endings or re-encoding headers, so every header and MIME boundary is preserved verbatim. The supplied text must be plain text (no raw non-text binary bytes).

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Imap
oleobject loo_Email
string ls_MimeText

li_Success = 0

//  Demonstrates the Imap.AppendMime method, which uploads a complete MIME message to a mailbox.
//  The 1st argument is the destination mailbox name and the 2nd is the MIME text.

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

//  Obtain the MIME text to upload.  Here it is generated from the Email, but it could equally
//  be read from a .eml file.
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

//  Append (upload) the MIME to the "Drafts" mailbox.
li_Success = loo_Imap.AppendMime("Drafts",ls_MimeText)
if li_Success = 0 then
    Write-Debug loo_Imap.LastErrorText
    destroy loo_Imap
    destroy loo_Email
    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
    return
end if



destroy loo_Imap
destroy loo_Email