PowerBuilder
PowerBuilder
Fetch a Single IMAP Message into an Email Object
See more IMAP Examples
Demonstrates the Chilkat Imap.FetchEmail method, which downloads one message (or its headers) into an Email object. The arguments are headerOnly, the message id, bUid (UID vs sequence number), and the Email that receives the message. This example fetches message 1 in full and reads its subject and from.
Background:
FetchEmail parses a downloaded message into a fully navigable Email object, giving you its subject, sender, body, and attachments. Passing headerOnly = true downloads just the headers — a fast way to build a message-list preview — after which you can fetch the full message on demand. Because a mailbox must be selected first, and fetching a full message can set the \Seen flag, use ExamineMailbox instead of SelectMailbox when you must not change read state.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Imap
oleobject loo_Email
li_Success = 0
// Demonstrates the Imap.FetchEmail method, which downloads one message (or its headers) into
// an Email object. The 1st argument is headerOnly, the 2nd is the message id, the 3rd
// (bUid) selects UID vs sequence number, and the 4th is the Email that receives the message.
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
li_Success = loo_Imap.SelectMailbox("Inbox")
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
return
end if
// Download message sequence number 1 in full. headerOnly=0, bUid=0.
loo_Email = create oleobject
li_rc = loo_Email.ConnectToNewObject("Chilkat.Email")
li_Success = loo_Imap.FetchEmail(0,1,0,loo_Email)
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
destroy loo_Email
return
end if
Write-Debug "Subject: " + loo_Email.Subject
Write-Debug "From: " + loo_Email.From
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