/ Published in: C#
URL: http://hellowebapps.com/wp-content/uploads/2010/07/ImapX_1.2.3.126.zip
Hacked together 10/01/2010\r\n\r\nPosted about it here:\\http://www.donationcoder.com/Forums/bb/index.php?topic=24148.0\r\n\r\nDownload sample solution from here:\\r\\nhttp://www.glensforkumc.com/non_church/csSampleSolutions/MyIMAP.zip Note: the sample solution contains the ImapX.dll file
Expand |
Embed | Plain Text
/* Required for this example: * * a C# WinForms application * add reference to ImapX.dll available here: * http://hellowebapps.com/wp-content/uploads/2010/07/ImapX_1.2.3.126.zip * http://dl.dropbox.com/u/12124382/ImapX.zip * a button <button1> * a textbox <textBox1> * * Notes: I used a very specific Subject line as my search criteria, but you need not do this. You could * just as easily have your code search through and download each and every email and/or every email's attachments. */ bool result = client.Connection(); if (result) { result = client.LogIn("myself@gmail.com", "mypassword"); if (result) { textBox1.AppendText(Environment.NewLine + Environment.NewLine + "Log-on successful" + Environment.NewLine + Environment.NewLine); ImapX.FolderCollection folders = client.Folders; foreach (ImapX.Message m in client.Folders["INBOX"].Messages) { m.Process(); if (m.Subject == "test email with 3 attachments (txt, png, wav)") { textBox1.AppendText(Environment.NewLine + Environment.NewLine + "Found email in question..." + Environment.NewLine + Environment.NewLine); string path = Application.StartupPath + "\\email\\"; string filename = "TxtPngWav"; //comment-out following line if you don't want to d/l the actual email m.SaveAsEmlToFile(path, filename); //use above line, and comment out the following if(){}, if you prefer to download the whole //email in .eml format if (m.Attachments.Count > 0) { for (int i = 0; i < m.Attachments.Count; i++) { m.Attachments[i].SaveFile(path); textBox1.AppendText("Saved attachment #" + (i + 1).ToString()); textBox1.AppendText(Environment.NewLine + Environment.NewLine); } } } } } } else { textBox1.AppendText("connection failed"); }
You need to login to post a comment.
