Awesome, Wraith! Thanks!!
I'll share my own cool discovery:
I run a roleplaying game on
www.myth-weavers.com at
http://www.myth-weav...mdisplay.php?f=11199I've been developing an application for my players that will allow them to create a new character and submit it to me, their Game Master, as an email attachment, for my perusal and approval. In thinking ahead to the Game Master application I'll be creating at some point, one of the functions I want it to have is that it automatically checks my Gmail account when the application starts, to see if any players have emailed me any character files.
Well, I've experimented until I found a way to do this.
The following brief code snippet is simply proof of concept. It uses the free
ImapX DLL. In my example below, I set a Subject Line to look for that signals my program I've found the right email (in this case "myflag"). Then, it looks through my Gmail emails until it finds such an email, and downloads the email itself as a *.eml file, and saves the first attachment to the same directory.
This snippet is very crude, but could be refined to download all attachments (if there are more than one). I could build in error-checking to ensure there IS an attachment before trying to save it to file, etc.
ImapX.ImapClient client = new ImapX.ImapClient("imap.gmail.com", 993, true);
bool result = client.Connection();
if (result) {
result = client.LogIn("
[email protected]", "myPassword");
if (result) {
ImapX.FolderCollection folders = client.Folders;
foreach (ImapX.Message m in client.Folders["INBOX"].Messages)
{
m.Process();
if (m.Subject == "myflag") {
string path = Application.StartupPath + "\\email\\";
string filename = "myEmail";
m.SaveAsEmlToFile(path, filename);
m.Attachments[0].SaveFile(path);
}
}
}
}
else {
MessageBox.Show("connection failed");
}