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.
Chilkat.Imap imap = new Chilkat.Imap(); bool success; // Anything unlocks the component and begins a fully-functional 30-day trial. success = imap.UnlockComponent("Anything for 30-day trial"); if (success != true) { MessageBox.Show(imap.LastErrorText); return; } // Connect to an IMAP server. success = imap.Connect("mail.chilkatsoft.com"); if (success != true) { MessageBox.Show(imap.LastErrorText); return; } // Login success = imap.Login("***","***"); if (success != true) { MessageBox.Show(imap.LastErrorText); return; } // Select an IMAP mailbox success = imap.SelectMailbox("Inbox"); if (success != true) { MessageBox.Show(imap.LastErrorText); return; } Chilkat.Email email; int uid; uid = 2014; bool isUid; isUid = true; email = imap.FetchSingle(uid,isUid); if (!(email == null )) { // Display the From and Subject textBox1.Text += email.FromAddress + "\r\n"; textBox1.Refresh(); textBox1.Text += email.Subject + "\r\n"; 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 += "---- EMAIL BODY ----" + "\r\n"; textBox1.Refresh(); textBox1.Text += email.Body + "\r\n"; textBox1.Refresh(); textBox1.Text += "--------------------" + "\r\n"; textBox1.Refresh(); // Display the recipients: int j; for (j = 0; j <= email.NumTo - 1; j++) { textBox1.Text += email.GetToName(j) + ", " + email.GetToAddr(j) + "\r\n"; textBox1.Refresh(); } for (j = 0; j <= email.NumCC - 1; j++) { textBox1.Text += email.GetCcName(j) + ", " + email.GetCcAddr(j) + "\r\n"; textBox1.Refresh(); } // Show the total size of the email, including body and attachments: textBox1.Text += email.Size + "\r\n"; 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: int numAttach; numAttach = imap.GetMailNumAttach(email); textBox1.Text += Convert.ToString(numAttach) + "\r\n"; textBox1.Refresh(); for (j = 0; j <= numAttach - 1; j++) { textBox1.Text += imap.GetMailAttachFilename(email,j) + "\r\n"; textBox1.Refresh(); int attachSize; attachSize = imap.GetMailAttachSize(email,j); textBox1.Text += " size = " + Convert.ToString(attachSize) + " bytes" + "\r\n"; textBox1.Refresh(); } textBox1.Text += "--" + "\r\n"; textBox1.Refresh(); } // Disconnect from the IMAP server. imap.Disconnect(); |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2008 Chilkat Software, Inc. All Rights Reserved.