Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
Fetch Single Email by UID or Sequence NumberAssuming the UID is known, download a single email by UID from an IMAP mail server.
Dim imap As New Chilkat.Imap() Dim success As Boolean ' Anything unlocks the component and begins a fully-functional 30-day trial. success = imap.UnlockComponent("Anything for 30-day trial") If (success <> true) Then MsgBox(imap.LastErrorText) Exit Sub End If ' Connect to an IMAP server. success = imap.Connect("mail.chilkatsoft.com") If (success <> true) Then MsgBox(imap.LastErrorText) Exit Sub End If ' Login success = imap.Login("***","***") If (success <> true) Then MsgBox(imap.LastErrorText) Exit Sub End If ' Select an IMAP mailbox success = imap.SelectMailbox("Inbox") If (success <> true) Then MsgBox(imap.LastErrorText) Exit Sub End If Dim email As Chilkat.Email Dim uid As Long uid = 2014 Dim isUid As Boolean isUid = true email = imap.FetchSingle(uid,isUid) If (Not (email Is Nothing )) Then ' Display the From and Subject TextBox1.Text = TextBox1.Text & email.FromAddress & vbCrLf TextBox1.Refresh() TextBox1.Text = TextBox1.Text & email.Subject & vbCrLf TextBox1.Refresh() ' Display the Body property, which is the default body. ' If an email has an HTML body, the Body property contains ' the HTML source. Otherwise it contains the plain-text ' body. TextBox1.Text = TextBox1.Text & "---- EMAIL BODY ----" & vbCrLf TextBox1.Refresh() TextBox1.Text = TextBox1.Text & email.Body & vbCrLf TextBox1.Refresh() TextBox1.Text = TextBox1.Text & "--------------------" & vbCrLf TextBox1.Refresh() ' Display the recipients: Dim j As Long For j = 0 To email.NumTo - 1 TextBox1.Text = TextBox1.Text & email.GetToName(j) _ & ", " & email.GetToAddr(j) & vbCrLf TextBox1.Refresh() Next For j = 0 To email.NumCC - 1 TextBox1.Text = TextBox1.Text & email.GetCcName(j) _ & ", " & email.GetCcAddr(j) & vbCrLf TextBox1.Refresh() Next ' Show the total size of the email, including body and attachments: TextBox1.Text = TextBox1.Text & email.Size & vbCrLf TextBox1.Refresh() ' When a full email is downloaded, we would use the ' email.NumAttachments property in conjunction with the ' email.GetMailAttach* methods. ' However, when an email object contains only the header, ' we need to access the attachment info differently: Dim numAttach As Long numAttach = imap.GetMailNumAttach(email) TextBox1.Text = TextBox1.Text & numAttach & vbCrLf TextBox1.Refresh() For j = 0 To numAttach - 1 TextBox1.Text = TextBox1.Text & imap.GetMailAttachFilename(email,j) & vbCrLf TextBox1.Refresh() Dim attachSize As Long attachSize = imap.GetMailAttachSize(email,j) TextBox1.Text = TextBox1.Text & " size = " _ & attachSize & " bytes" & vbCrLf TextBox1.Refresh() Next TextBox1.Text = TextBox1.Text & "--" & vbCrLf TextBox1.Refresh() End If ' Disconnect from the IMAP server. imap.Disconnect() |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2007 Chilkat Software, Inc. All Rights Reserved.