0

Part of the program I'm designing needs to "read" and place the main body of an E-Mail, from a g-mail account if possible, into a string.

What do I do? I'm pretty lost when it comes to C#-to-web interactions..

Any help or resources would be appreciated!

To clarify, I want to process the E-Mails when they are received, not all of them at once.

Frostytheswimmer
  • 720
  • 4
  • 19

2 Answers2

0

From stackoverflow

I found GMailAtomFeed

   // Create the object and get the feed 
   RC.Gmail.GmailAtomFeed gmailFeed = new RC.Gmail.GmailAtomFeed("username", "password"); 
   gmailFeed.GetFeed(); 

   // Access the feeds XmlDocument 
   XmlDocument myXml = gmailFeed.FeedXml 

   // Access the raw feed as a string 
   string feedString = gmailFeed.RawFeed 

   // Access the feed through the object 
   string feedTitle = gmailFeed.Title; 
   string feedTagline = gmailFeed.Message; 
   DateTime feedModified = gmailFeed.Modified; 

   //Get the entries 
   for(int i = 0; i < gmailFeed.FeedEntries.Count; i++) { 
      entryAuthorName = gmailFeed.FeedEntries[i].FromName; 
      entryAuthorEmail = gmailFeed.FeedEntries[i].FromEmail; 
      entryTitle = gmailFeed.FeedEntries[i].Subject; 
      entrySummary = gmailFeed.FeedEntries[i].Summary; 
      entryIssuedDate = gmailFeed.FeedEntries[i].Received; 
      entryId = gmailFeed.FeedEntries[i].Id; 
   }

also you should look

http://code.msdn.microsoft.com/CSharpGmail

http://weblogs.asp.net/satalajmore/archive/2007/12/19/asp-net-read-email.aspx

As for processing them as they come, you will just have to set up a process to poll for new mail.

Community
  • 1
  • 1
crthompson
  • 15,653
  • 6
  • 58
  • 80
0

For reference,

Using the S22.Imap package on nugit

using (var client = new ImapClient("imap.gmail.com", 993,
         "username", "password", AuthMethod.Login, true))
        {
            var uids = client.Search(SearchCondition.Unseen());
            if (uids.Length >= 1)
            {
                var message = client.GetMessage(uids[0], false, "inbox");
                return new MessageInfo {EnclosedText = message.Body, Sender = message.From.ToString()};
            }
            return new MessageInfo();

        }
Frostytheswimmer
  • 720
  • 4
  • 19