PowerBuilder
PowerBuilder
Append (Upload) an Email to an IMAP Mailbox
See more IMAP Examples
Demonstrates the Chilkat Imap.AppendMail method, which uploads an Email object to a mailbox on the server. The first argument is the destination mailbox name and the second is the Email. After a successful append, the AppendUid property holds the UID the server assigned (or 0 if none was reported). This example uploads a newly built message to the Drafts mailbox.
Background: The IMAP
APPEND command lets a client add a message directly to any mailbox without sending it through SMTP — it is how "Save to Drafts" works, and how a client keeps its own copy in Sent. The initial \Seen state is governed by the AppendSeen property (or by the flag arguments of the AppendMimeWithFlags variants).Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Imap
oleobject loo_Email
li_Success = 0
// Demonstrates the Imap.AppendMail method, which uploads an Email object to a mailbox on the
// server. The 1st argument is the destination mailbox name and the 2nd is the Email.
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."
// Append (upload) the email to the "Drafts" mailbox.
li_Success = loo_Imap.AppendMail("Drafts",loo_Email)
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
destroy loo_Email
return
end if
// AppendUid holds the UID assigned by the server (0 if the server did not report one).
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