1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

C#: Email Verficiation?

Discussion in 'C, C++, C#' started by kytro360, Aug 10, 2011.

  1. kytro360

    kytro360 Power Member

    Joined:
    Jan 12, 2010
    Messages:
    703
    Likes Received:
    733
    How can I make my program verify emails?
     
  2. Baybo.it

    Baybo.it Registered Member

    Joined:
    Aug 9, 2011
    Messages:
    72
    Likes Received:
    39
    Occupation:
    Founder of Baybo.it
    Location:
    San Francisco
    Home Page:
    You can attempt to verify an email is correct by constructing a regular expression in C#. Regular expressions is a method for pattern matching closed under regular language (see computational theory). Regular expressions (regex for short) has a set of rules which one must understand before using the language. Here are some common examples of character classes in regex using some of the major operators:

    [0-9] matches any single digit
    [0-9]? matches none or 1 digit
    [0-9]* matches none or more digits
    [0-9]+ matches 1 or more digits
    [0-9a-zA-Z_]+ matches a string of characters containing any number 0-9 and any letter (either lowercase or uppercase) and _'s. An example match for this regex could be 01a8adji_9sd

    Let's choose an example regex:
    [0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]
    This would an extremely (and over simplified) regex for phone numbers (no area code, assuming xxx-xxxx format)

    This post isn't complete, I cannot yet post links and thus my original response was throwing moderator warnings. In process of re-writing solution.
     
  3. Baybo.it

    Baybo.it Registered Member

    Joined:
    Aug 9, 2011
    Messages:
    72
    Likes Received:
    39
    Occupation:
    Founder of Baybo.it
    Location:
    San Francisco
    Home Page:
    As a follow up to my original post:

    Now, email addresses are a bit more complicated and we still need to know how to apply regex in C#. The code will look something like this:

    NOTE: Since my regex looked similar to an email, the filters prevent me from submitting it. As a result, I have put my code at a separate location. I apologize for the inconvenience. Code at:
    pastebin /37nKMQRk -- note, this is actually a link to pastebin . sea oh em, slash, 37nKMQRk.

    Sorry, still cannot post links -- it's pretty ridiculous. Hope it works for you

    Ultimately, the regex you want will follow these rules:
    1. An email starts with any number of digits, letters, underscores, or periods, etc.
    2. Followed by a .
    3. Followed by any number of digits, letters, underscores, or periods, etc.
    4. Followed by an at symbol
    5. Followed by any number of digits, letters, underscores, or periods, etc.

    It depends on the level of accuracy you need. As per the RFC 822 compliant regex spec, there isn't a master formula which will match all emails. There are many exceptions to the above regex, like emals containing +'s in them, etc.

    Hope this at least points you in the right direction!
     
    Last edited: Aug 10, 2011
  4. dangerbear

    dangerbear Newbie

    Joined:
    Apr 3, 2011
    Messages:
    4
    Likes Received:
    1
    Occupation:
    Software Developer
    Location:
    India
    As Baybo.it suggest you can use regex.
    If you want to verify that the user is valid you can send out an email with a verification link and then make the user click it.
    If you want detailed source code or sample reply.
     
  5. kytro360

    kytro360 Power Member

    Joined:
    Jan 12, 2010
    Messages:
    703
    Likes Received:
    733
    Thanks Baybo. Quick question is the code to verify if an email is valid? What Im trying to do is an email verification so for example my program goes into my users email and clicks the links in certain emails to verify their accounts on several sites. Sorry for the mixup :/
     
    Last edited: Aug 10, 2011
  6. Baybo.it

    Baybo.it Registered Member

    Joined:
    Aug 9, 2011
    Messages:
    72
    Likes Received:
    39
    Occupation:
    Founder of Baybo.it
    Location:
    San Francisco
    Home Page:
    If you are trying to verify that an email actually belongs to a user, and not that the email itself is of valid format, dangerbear offers a good solution.

    You can automate the process of sending the end-user a verification email with a unique generated link (which can only be access via their email). If you do this, you can verify that the email is active and belongs to the correct user.

    As a programmer, I tend to develop these email activation messages with a home-built solution, however, there are several services for email registration, like constantcontact.

    Can you tell us a little more about your situation / budget / skill set and maybe we can offer you further guidance?

    Also, when you say writing a program to verify emails, are you suggesting you'd like to write a macro or program which goes through YOUR inbox and clicks the link to certain activation messages? Or sending out email activations to users of some service / on some mailing list?

    Sorry for the initial misunderstanding and best of luck with email verification!
     
    Last edited: Aug 10, 2011
  7. kytro360

    kytro360 Power Member

    Joined:
    Jan 12, 2010
    Messages:
    703
    Likes Received:
    733
    Well Im am trying to program my own SEO automation program. Basically it helps you build backlinks. Basically it lets you create accounts on several sites and I want my program to go to Hotmail, Yahoo, GMail,etc. and click on the emails they received for registering on the site sites and a certain link inside the email to confirm their accounts.
     
  8. Baybo.it

    Baybo.it Registered Member

    Joined:
    Aug 9, 2011
    Messages:
    72
    Likes Received:
    39
    Occupation:
    Founder of Baybo.it
    Location:
    San Francisco
    Home Page:
    I see. You will have to integrate with each of the authentication modules for each individual email server. For instance, you may consider writing a binding for google's gmail over IMAP or SMTP using OAuth (assuming a binding doesn't already exist for c#, which I'm sure it does). In general, this is a non trivial problem as you have to interface with a variety of secure interfaces.

    Essentially what you'd have to do is produce a script which performs a secure login via the method published by each provider (yahoo, google, etc) and then write a script which GETs or POSTs each request internally. You'll then need to use some mail client package (sendmail is the common one) to send out an email. Checking mail can be done fairly easily if you have access to the account, simply my iterating over the messages. There really is no concept of 'clicking' though. Instead, when a message is queried and accessed, this is equivalent to it being 'read'.

    It depends how you want to accomplish this. If you intend for this to be a standalone program which anyone can run on any machine, you're in for a long development process -- this is not trivial.

    However, if you are simply trying to write a script which parses the mail on your local machine and can provide the access credentials manually without interfacing with an API, it shouldn't be too challenging at all.

    I hope this sheds a little light on the problem.
     
    Last edited: Aug 11, 2011
  9. kytro360

    kytro360 Power Member

    Joined:
    Jan 12, 2010
    Messages:
    703
    Likes Received:
    733
    Can you point me to some tutorials on how to accomplish this? I havent worked with POP3 clients at all.

    Also is it possible to do this in the webbrowser?
     
  10. Bots_Do_it_Faster

    Bots_Do_it_Faster Registered Member

    Joined:
    Jun 28, 2010
    Messages:
    64
    Likes Received:
    77
    Occupation:
    Web Developer php and c#
    Location:
    South Florida
    You can do it with webbrowser, but just reading the mail from pop3 is much easier. If you are going to use gmail not that they require a ssl connection and there are special modifications to the normal packages for reading pop3.

    Basically you would parse the pop3 looking for the email with the activation link. Then you would trigger a webbrowser or httpwebrequest to trigger the activation link.

    http://stackoverflow.com/questions/44383/reading-email-using-pop3-in-c

    That link should get you started
     
  11. kytro360

    kytro360 Power Member

    Joined:
    Jan 12, 2010
    Messages:
    703
    Likes Received:
    733
    Thanks @Bots for the article. It should give me some insight hopefully
     
  12. Xooor

    Xooor Newbie

    Joined:
    Aug 14, 2011
    Messages:
    18
    Likes Received:
    17
    What a lot of people do, thought it's a very dirty solution is basically simulate a web browser using native components in C#. I had a job where I had to port one of those bots from .Net (Windows) to Mono (Linux).

    So that's a possible solution, but the cleanest solution would be to try to "reverse engineer the whole process" and write a custom bot to do so.

    If you have any experience with Python, a few good libs for writing bots are Urllib and Urllib2, BeautifulSoup ...
     
  13. kytro360

    kytro360 Power Member

    Joined:
    Jan 12, 2010
    Messages:
    703
    Likes Received:
    733
    I tried to do it in the webbrowser but i couldnt figure it out
     
  14. haylander

    haylander Registered Member

    Joined:
    May 24, 2009
    Messages:
    54
    Likes Received:
    20
    before using regex , you need to decode email (base16,base64,quoted printable etc...).
    this is the hardest part i encountered when automating validation as there is no .Net library to decode/encode them.
     
  15. something77

    something77 Registered Member

    Joined:
    Jan 6, 2010
    Messages:
    73
    Likes Received:
    10
    There are many examples of how to do it online and I remember finding two dlls with guide. I use the ImapX dll, am not sure this is the home page, but looks good
    http://hellowebapps.com/products/imapx/


    and for
    No point using a webbrowser, just pull the page
    Code:
    WebClient webClient = new WebClient();
     webClient.DownloadString(_verificationLink);
     
    Last edited: Sep 6, 2011
  16. darkmonk

    darkmonk Regular Member

    Joined:
    Nov 21, 2007
    Messages:
    226
    Likes Received:
    52
    This is a little bit older but it might give you a push in the right direction:
    Code:
    http://archive.msdn.microsoft.com/CSharpGmail
    And here's an even older POP3 client in C#, might give you a starting point:
    Code:
    http://www.codeproject.com/KB/IP/despop3client.aspx
     
  17. sirgold

    sirgold Supreme Member

    Joined:
    Jun 25, 2010
    Messages:
    1,260
    Likes Received:
    645
    Occupation:
    Busy proving the Pareto principle right
    Location:
    A hot one
    Chilkat OP or straight sockets thru SSL will get the thing done if you can access pop3 / imap.
     
  18. xenon2010

    xenon2010 Regular Member

    Joined:
    Apr 27, 2010
    Messages:
    231
    Likes Received:
    48
    Occupation:
    web and desktop apps programmer
    Location:
    prison
    Home Page:
    Chilkat is not for free... Use IMAPX instead. very easy to use, very handy and the best thing its for free.. from my personal experience I prefer to use IMAP to download the emails from the server. POP3 will just download the emails and then automatically delete them from the server which is not a good choice if you have stored important email and you don't want to lose it. still not all email providers support IMAP for free but the best ones do support that i.e. Gmail and Yahoo Mail Plus (its not for free) but with some simple hacks you can make it available for free.. as for MSN as far as I know it doesn't support IMAP. but it does support POP3 with limited functionality...

    so go for IMAPX it does support search and more cool stuff...