Introduction
What the article/code snippet does, why it's useful, the problem it solves etc.
Background
(Optional) Is there any background to this article that may be useful such as an introduction to the basic ideas presented?
Using the code
A brief description of how to use the article or code. The class names, the methods and properties, any tricks or tips.
Blocks of code should be set as style "Formatted" like this:
private delegate void IUThread();
private void btnDownload_Click(object sender, RoutedEventArgs e)
{
Thread objThread = new Thread(new ThreadStart(DownloadMail));
objThread.Start();
}
private void DownloadMail()
{
DataTable dtRows = new DataTable();
dtRows.Columns.Add("FromId", typeof(string));
dtRows.Columns.Add("Date", typeof(string));
dtRows.Columns.Add("Subject", typeof(string));
dtRows.Columns.Add("No", typeof(string));
#region Gmail
#endregion
#region Yahoo
string host = "imap.mail.yahoo.com";
string username = "">userName@yahoo.com";
string password = "";
#endregion
#region ImapExample
TcpIMAP imap = new TcpIMAP();
imap.Connect(host, 993);
//--> This is Gmail User Authentication.
#region Gmail Authentication User
//imap.AuthenticateGmailUser(username, password);
#endregion
//--> This is Yahoo User Authentication.
#region Yahoo Authentication User
imap.AuthenticateYahooUser(username, password);
#endregion
mailCount = imap.MailCount();
imap.MailUnreadCount();
// You need to select the inbox in order to view the your messages
imap.SelectInbox();
string sSubjectToTrap = "";
string sFromIdToTrap = "";
string sDateTime = "";
/*
* Uncomment code below to get the message header and body for the
* first message in your mailbox.
* */
try
{
for (int i = 1; i <= mailCount; i++)
{
dump = (string)imap.GetMessageHeaders(i);
if (dump.Contains("Subject"))
{
sSubjectToTrap = hlprCapStr(dump, "Subject:").Trim();
sFromIdToTrap = hlprCapStr(dump, "From:").Trim();
sFromIdToTrap = sFromIdToTrap.Substring(sFromIdToTrap.IndexOf("<") + 1);
sFromIdToTrap = sFromIdToTrap.Replace(">", "");
sDateTime = hlprCapStr(dump, "Date:").Trim();
this.Dispatcher.BeginInvoke((IUThread)delegate
{
dtRows.Rows.Add(sSubjectToTrap, sDateTime, sFromIdToTrap, i);
dtMail.ItemsSource = dtRows.DefaultView;
progressMail.Value = System.Convert.ToDouble(i) / System.Convert.ToDouble(mailCount) * 100;
}
);
}
}
}
catch(Exception)
{
}
finally
{
MessageBox.Show("Congratulation you done...!!" + " " + mailCount + " Mail");
imap.Disconnect();
}
#endregion
}
Remember to set the Language of your code snippet using the Language dropdown.
Use the "var" button to to wrap Variable or class names in <code> tags like this
.
Points of Interest
Did you learn anything interesting/fun/annoying while writing the code? Did you do anything particularly clever or wild or zany?
History
Keep a running update of any changes or improvements you've made here.