Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 1st Oct 2011, 03:06 PM   #1
Senior Warrior Member
War Room Member
 
Edwin Torres's Avatar
 
Join Date: 2010
Posts: 1,596
Thanks: 276
Thanked 515 Times in 263 Posts
Default
C#: How to parse emails?
Share on: 
fb share twitter share gplus share more share

Hi,

Anyone know the code or how to parse through emails that a site gives you and click the links inside of them. Im using the dll OpenPop3 but so far have only figured out how to login.

Any help would be appreciated

Edwin Torres is offline  
Unread 1st Oct 2011, 04:55 PM   #2
HyperActive Warrior
 
unnatural's Avatar
 
Join Date: 2011
Location: Edmonton, Alberta
Posts: 120
Thanks: 0
Thanked 25 Times in 23 Posts
Default
Re: C#: How to parse emails?
Share on: 
fb share twitter share gplus share more share

Just download the emails with the POP3 connection, then you can use the following regex to match all the links.

#(http|https|ftp)://([A-Z0-9][A-Z0-9_-]*(?:.[A-Z0-9][A-Z0-9_-]*)+):?(d+)?/?#i
unnatural is offline  
Unread 1st Oct 2011, 05:00 PM   #3
Senior Warrior Member
War Room Member
 
Edwin Torres's Avatar
 
Join Date: 2010
Posts: 1,596
Thanks: 276
Thanked 515 Times in 263 Posts
Default
Re: C#: How to parse emails?
Share on: 
fb share twitter share gplus share more share

Can I use OpenPop3 or do I use the built in support for POP3 that C# brings?
Edwin Torres is offline  
Unread 1st Oct 2011, 05:07 PM   #4
HyperActive Warrior
 
unnatural's Avatar
 
Join Date: 2011
Location: Edmonton, Alberta
Posts: 120
Thanks: 0
Thanked 25 Times in 23 Posts
Default
Re: C#: How to parse emails?
Share on: 
fb share twitter share gplus share more share

I checked out OpenPop3 on SourceForge but I don't see any files or examples so I can't tell you for sure. I imagine its just a helper library to communicate with the built in POP3 functions so I don't see why not, try reading the documentation.

Also, I found another similar library called OpenPop OpenPop.NET | Free Communications software downloads at SourceForge.net which seems to actually have files to download and it says it supports all the common POP3 functions and email MIME types.
unnatural is offline  
Unread 1st Oct 2011, 05:54 PM   #5
Senior Warrior Member
War Room Member
 
Edwin Torres's Avatar
 
Join Date: 2010
Posts: 1,596
Thanks: 276
Thanked 515 Times in 263 Posts
Default
Re: C#: How to parse emails?
Share on: 
fb share twitter share gplus share more share

This is what I have so far:

Code:
 Pop3Client client = new Pop3Client();
            client.Connect("pop3.live.com", 995, true);
            client.Authenticate("USER", "PASSWORD");
            label18.Text = client.GetMessageCount().ToString();
            int messageCount = client.GetMessageCount();


            for (int i = 1; i <= messageCount; i++)
            {
                // Download the header and check if the message is interesting
                // enough to download if with body
                MessageHeader header = client.GetMessageHeaders(i);
                if ("Wordpress".Contains(header.Subject))
                {
                    // The message is interesting - download it
                    OpenPop.Mime.Message message = client.GetMessage(i);

                    // Find the first part containing HTML
                    // null is returned if such part is not found
                    MessagePart html = message.FindFirstHtmlVersion();
                    if (html != null)
                    {
                        String htmlContained = html.GetBodyAsText();
                        // Do something with the html
                        // here showing it in a listbox
                        richTextBox1.Text = htmlContained;
                    }
                }
            }
            client.Disconnect();
Edwin Torres is offline  
Unread 3rd Oct 2011, 10:03 AM   #6
HyperActive Warrior
 
LakiPolitis's Avatar
 
Join Date: 2011
Location: West Palm Beach, FL
Posts: 113
Thanks: 7
Thanked 12 Times in 11 Posts
Default
Re: C#: How to parse emails?
Share on: 
fb share twitter share gplus share more share

You could looks for the characters "<a href", then split the strings up til you find the immediate next "</a>". Then add all those split strings into a generic list.

Once they're in a generic list you can bind that list to a repeater, and dynamically create them as a page you could click the links on.

Here's some info on generic lists: An Introduction to C# Generics

LakiPolitis is offline  
Unread 3rd Oct 2011, 08:53 PM   #7
Software/Database Expert
War Room Member
 
gtownfunk's Avatar
 
Join Date: 2011
Location: Austin, TX
Posts: 75
Thanks: 47
Thanked 24 Times in 21 Posts
Default
Re: C#: How to parse emails?
Share on: 
fb share twitter share gplus share more share

I know it looks like a bunch of gobbleygook, but you should really use the Regular Expression method that unnatural posted. C# has a great Regular Expression library and there is tons of free sample code out there. You can literally parse ALL LINKS out of an email in 3-4 lines of code.

gtownfunk
gtownfunk is offline  
Closed Thread


Bookmarks

Tags
c sharp, email, emails, openpop, parse


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 05:57 PM.