Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
Download IMAP Email Headers C# sample code to download email headers from an IMAP mailbox and display From, To, CC, Subject, Date, and Attachment information. private void button3_Click(object sender, System.EventArgs e)
{
// Read email headers and display the FROM, Subject, To, CC,
// Date, and Attachment info.
Chilkat.Imap imap = new Chilkat.Imap();
imap.UnlockComponent("Anything for 30-day trial");
// If your IMAP server needs SSL, set the Ssl property = true
// and set the IMAP port to 993.
// imap.Ssl = true;
// imap.Port = 993;
imap.Connect("mail.chilkatsoft.com");
// Login to an email account.
bool b = imap.Login("mylogin", "mypassword");
if (!b)
{
MessageBox.Show("Login Failed!");
return;
}
// Select the mailbox to read.
b = imap.SelectMailbox("INBOX");
if (!b)
{
MessageBox.Show(imap.LastErrorText);
return;
}
// Get a message set containing all the message IDs
// in the selected mailbox.
bool fetchUids = true;
Chilkat.MessageSet mset = imap.Search("ALL",fetchUids);
// Fetch the email headers into an email bundle.
Chilkat.EmailBundle bundle = imap.FetchHeaders(mset);
if (bundle == null)
{
MessageBox.Show("Failed to fetch headers!");
imap.SaveLastError("errorLog.xml");
return;
}
// Loop over each e-mail in the bundle and display information:
int i;
for (i=0; i<bundle.MessageCount; i++)
{
Chilkat.Email email = bundle.GetEmail(i);
listBox1.Items.Add("From: " + email.From);
listBox1.Items.Add("Subject: " + email.Subject);
listBox1.Items.Add(Convert.ToString(email.LocalDate));
int numTo = email.NumTo;
int j;
for (j=0; j<numTo; j++)
{
listBox1.Items.Add("To: " + email.GetTo(j));
}
int numCC = email.NumCC;
for (j=0; j<numCC; j++)
{
listBox1.Items.Add("CC: " + email.GetCC(j));
}
// NOTE: The BCC recipients are not available in downloaded
// email.
// Now show attachment information. Because we downloaded
// the headers, the email.NumAttachments property will always
// equal 0. The email.NumAttachments property is set correctly
// only when the full emails are downloaded. Instead, use the
// imap.GetMailNumAttach method.
int numAttach = imap.GetMailNumAttach(email);
for (j=0; j<numAttach; j++)
{
string attachmentFilename = imap.GetMailAttachFilename(email,j);
int attachmentSize = imap.GetMailAttachSize(email,j);
listBox1.Items.Add("Attachment: " + attachmentFilename + ", " +
Convert.ToString(attachmentSize) + " bytes");
}
listBox1.Items.Add("---------------------------------");
}
// Disconnect from the IMAP server.
imap.Logout();
imap.Disconnect();
}
Important: The download for this
example does not contain the ChilkatDotNet.dll which |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2008 Chilkat Software, Inc. All Rights Reserved.