asp tutorials, asp.net tutorials, sample code, and Microsoft news from 15Seconds
Data Access  |   Troubleshooting  |   Security  |   Performance  |   ADSI  |   Upload  |   Email  |   Control Building  |   Component Building  |   Forms  |   XML  |   Web Services  |   ASP.NET  |   .NET Features  |   .NET 2.0  |   App Development  |   App Architecture  |   IIS  |   Wireless
 
Pioneering Active Server
 Power Search








Active News
15 Seconds Weekly Newsletter
• Complete Coverage
• Site Updates
• Upcoming Features

More Free Newsletters
Reference
News
Articles
Archive
Writers
Code Samples
Components
Tools
FAQ
Feedback
Books
Links
DL Archives
Community
Messageboard
List Servers
Mailing List
WebHosts
Consultants
Tech Jobs
15 Seconds
Home
Site Map
Press
Legal
Privacy Policy
internet.commerce














internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

HardwareCentral
Compare products, prices, and stores at Hardware Central!

Using .NET and Excel 2003 To Validate E-Mails
By Calvin Luttrell
Rating: 3.6 out of 5
Rate this article


  • email this article to a colleague
  • suggest an article

  • download source code

    E-mail address validation is a topic I've written about on numerous occasions. Last year I wrote an article titled "Validating E-mail Against the Mail Server", which discussed using .NET to effectively validate e-mail addresses. The idea was to save time and resources by not sending e-mails to "bad" e-mail accounts.

    When organizations need to inspect and verify a list of e-mail addresses, sometimes it's nice to pop that list into Microsoft Excel, click a button that says "Who's your daddy," and receive a fairly reliable count of valid e-mail addresses -- even when you have obstacles like Yahoo!'s mail servers, which determine each and every e-mail address as valid.

    The issues with Yahoo! were hot topics when I first implemented this code into production, and they continue today. Every month I am left with the task of verifying well over 10,000 e-mail addresses-and a good portion of them are from Yahoo!.

    Yahoo!'s e-mail servers respond with an 'A-OK' to every e-mail address you try to send e-mail to. And although I can't quote the standards off-hand, I don't think that's exactly included in there. But regardless, there are some rules that can be bent while others can be broken, right?

    All Yahoo! e-mail addresses are connected to Yahoo! profiles. So, if the e-mail address is through Yahoo!, you are going to first hunt them down in Yahoo!'s profile pages. This is less complicated now because nothing is impossible with .NET.

    To address this, you will need to take the code from the validating e-mail Web service article and add the following function to that project.

    If you add the ThanksYahoo function to the validation Web service you will know if a user is valid or not, even if it's a Yahoo! address. What's hilarious is that this is actually less resource intensive, and it takes much less work to validate an e-mail than talking to the mail server. So when you come across BeenSwindled@yahoo.com, you will pass the username portion to this function to see if it's valid. As luck would have it, it is valid. (Someone should send this guy an inspiration Yahoo! e-card).

    This function will create a WebRequest object that will pull the HTML down from the Yahoo! profiles page. If a user is not present, it will respond with "user not found".

    
    Function ThanksYahoo(ByVal name As String) As Long
    
            Dim ret As String
            ' The Path to the Yahoo Quotes Service
            Dim fullpath As String = "http://profiles.yahoo.com/" + name
    
            '// Create a HttpWebRequest object on the Yahoo url
            Dim webreq As HttpWebRequest = WebRequest.Create(fullpath)
    
            '// Get a HttpWebResponse object from the Yahoo url
            Dim webresp As HttpWebResponse = webreq.GetResponse
    
            '// Create a StreamReader object and pass the Yahoo Server stream as a 
    parameter
            Dim strm As StreamReader
            strm = New StreamReader(webresp.GetResponseStream(), Encoding.ASCII)
    
            '// Read a single line from the stream (from the server) 
            '// We read only a single line, since the Yahoo server returns all the
            '// information needed by us in just one line.
    
            Return strm.ReadToEnd.IndexOf("User not found")
        End Function
    
    
    Now that Yahoo! is out of the way, on to the fun stuff.

    Microsoft Office 2003 has a new COM Interop for writing .NET code behind an Excel file-instead of using Visual Basic applications (VBA). This opens up a whole new world of possibilities for checking e-mail addresses in Excel. Now that your boss can check his own e-mail addresses, you can keep back to your EverQuest character. You can download the Interops from MSDN library.

    After you have legally obtained a list of e-mail prospects, you can see how many of them are worth anything. If you obtained your list from one of those new worm viruses, just remember that famous saying, "What goes around, comes around." To get started, you will need to have the Micorsoft Office 2003 Interops. But unless you have an MSDN subscription, or a copy of Office 2003, you might be out of luck.

    Once installed, Office 2003 Interops will provide you with more options and new project types in Visual Studio.

    Choose an Excel Workbook project from the New Project window. (If you would rather do one in Word, or anything else, I wish you good luck with that.) My very first programming project, at a little company called GoldMine Software, was to figure out how to read cells from Excel and update numbers in a CRM system. I spent 12 hours figuring out that project and loved it. So I was pretty delighted to return to Excel once again.

    When you create the project, Visual Studio will create an OfficeCodeBehind Class for you. This will give you access to the Excel object and events. Now that you have the setup, add a form to the project to display to the Excel user. This gives them the options to process the e-mail addresses in the workbook. In the ThisWorkbook_Open subroutine you're going to add this code, which creates the frmExcel form and displays it. You've also changed the form to accept an instance of the workbook object so you can gain access to the e-mail addresses in the worksheet.

    
    
            Dim oform As New frmExcel(ThisWorkbook)
            oform.Show()
    
    
    
    In the project you'll need to add a reference to the Web service. In the sample project for this article the Web reference points to projectthunder.com. However, that will not process requests for you. You will need to setup your own copy of the Web service and update the reference. In the form, add a button. Then add the following code to the click event for the button.
    
    
    Dim oSheet As Excel.Worksheet
            Dim oEmail As New com.projecthunder.IWAMFW.ValidateEmail
            Dim stemp As String
            Dim stemp2 As String
            oEmail.Timeout = 1000
    
    'Using the local instance of the worksheet. 
            oSheet = CType(_workbook.Worksheets.Item(1), Excel.Worksheet)
    
    'loop until there is nothing there
            For i As Integer = 1 To 900
    
                If oSheet.Range("C" + i.ToString).Text.ToString.Trim = "" Then
    
                    stemp = oSheet.Range("A" + i.ToString).Text.ToString
                    Try
                        stemp2 = oEmail.ChatMailServer(stemp).ToString
                    Catch
    'in case something dies
                        oEmail = New com.futuredontics.services.ValidateEmail
    
                    End Try
    
    'if something went wrong let's say we couldn't connect
                    If stemp2 <> "" Then
                        oSheet.Range("C" + i.ToString).Value = stemp2
                    Else
                        oSheet.Range("C" + i.ToString).Value = "3"
    
                    End If
                    stemp2 = ""
    
    
                End If
    
    'humor me and process windows messages although it seems to do nothing
                System.Windows.Forms.Application.DoEvents()
    
            Next
    
    
    
        End Sub
     
    
    
    If you're sharp you picked up on my Windows OLE API, which is an interface for setting up and displaying a compound document. This is nothing short of a hack to keep Excel 2003 from blowing up when the Web service takes a few more milliseconds than it cares to wait. You are just asking OLE to suppress a dialog that Excel presents when it is waiting for your Web service.

    The integration between Office and .NET is new. Please keep in mind that if your Web service is under a heavy load with requests, Excel may appear to be hung-up while it updates each one. You could change the code to read all the e-mail addresses into an array, then check all of them, and then write them back to Excel all at once. I personally prefer to see the Excel spreadsheet being updated one by one.

    You could use the older version of the Interop to do something similar with Office XP. Interop, I believe, is short for interoperability. Perhaps think of it as an underpaid translator between COM and the managed code world. But keep in mind that you must have the right version for your version of Office.

    In conclusion, using the Web service from the article "Validating E-mail Against the Mail Server",, you figured out how to deal with Yahoo! e-mail addresses by checking for a Yahoo! profile. You also learned how to consume that Web service from Excel 2003 using a Microsoft Office Systems Project.

    About the Author

    Calvin Luttrell has consistently utilized his knowledge of Microsoft Solutions to streamline projects such as the Web site for the Golden Globes, 1800Dentist.com, and various CRM integrated systems currently running across the planet.

    Prior to joining 1-800-DENTIST as a Senior Software Architect, Luttrell served as a Senior Support Engineer at GoldMine Software, a position in which he accredits his vast knowledge and experience in working effectively in all facets of development from communication to software architecture. Aside from 1-800-DENTIST, Luttrell also provides development consultation and training for small-to-medium consulting companies. He is currently working on ProjectThunder.com, a future project concerning effective team management and ways to increase production results within the Thunder Framework (which runs on DOT NET). Luttrell can be reached at Calvin@projectthunder.com.

  • Rate This Article
    Not HelpfulMost Helpful
    1 2 3 4 5
    Other Articles
    Jul 7, 2005 - Hosting Indigo Web Services
    In the second article of his series on Indigo web services, Chris Peiris explains how to host an Indigo web service and examines the IIS, self hosting, and Windows Activation Service hosting options. He then provides step-by-step instructions and sample code for an IIS-hosted and self-hosted Indigo web service.
    [Read This Article]  [Top]
    Jun 8, 2005 - Indigo Programming Model
    In the first part of his series on Microsoft Indigo, Chris Peiris examines the basics of SOA, explains how Indigo fits into the picture and the problems it solves. He then introduces Indigo's programming model and finishes by building a sample Indigo web service using the Microsoft .Net Framework 2.0.
    [Read This Article]  [Top]
    Nov 10, 2004 - Business Intelligence with Microsoft SQL Server Reporting Services - Part 3
    Adnan Masood concludes his discussion of Microsoft SQL Server Analysis services and Microsoft SQL Server Reporting services. In the final part, he discusses Reporting Server web services and using custom code in reports.
    [Read This Article]  [Top]
    Jul 8, 2004 - Using IE's Web Service Behavior To Create Rich ASP.NET Applications
    This article explains the features of the IE Web service behavior and shows how to asynchronously communicate with an ASP.NET Web service directly from the client.
    [Read This Article]  [Top]
    Jun 9, 2004 - Modifying Web Services Documentation
    This short article describes a quick and easy way to provide some security to an ASP.NET Web service by modifying its associated documentation file.
    [Read This Article]  [Top]
    Jun 2, 2004 - Kerberos Authentication with Web Services Enhancements 2.0
    Kerberos authentication is the cornerstone of Windows operating system authentication architecture. Web Services Enhancement 2.0 (WSE 2.0) extends Kerberos support to ASP.NET Web services. Chris Peiris explains the support for this new feature in WSE 2.0.
    [Read This Article]  [Top]
    Dec 15, 2003 - Realizing a Service-Oriented Architecture with .NET
    Chip Irek examines the architectural issues and component design issues of building a .NET application in a service-oriented architecture.
    [Read This Article]  [Top]
    Nov 24, 2003 - Consuming Asynchronous Web Services
    Thiru Thangarathinam shows how to use asynchronous Web services, Windows Service applications, server-based timer components and .NET XML API classes to create high-performance, scalable, and flexible applications.
    [Read This Article]  [Top]
    Nov 12, 2003 - Implementing Paging and XSLT Extensions Using XSLT in .NET - Part 2
    Part one showed how to transform XML data into HTML by using an XSL stylesheet from within a .NET application. This part explains how to make use of XSLT Extension objects and invoke a C# class method from an XSL stylesheet.
    [Read This Article]  [Top]
    Nov 5, 2003 - Implementing Paging and XSLT Extensions Using XSLT in .NET - Part 1
    Learn how to transform XML data into HTML by using an XSL stylesheet from within a .NET application, and then implement a paging solution by declaring and supplying paging parameters to the stylesheet.
    [Read This Article]  [Top]
    Mailing List
    Want to receive email when the next article is published? Just Click Here to sign up.

    Support the Active Server Industry



    JupiterOnlineMedia

    internet.comearthweb.comDevx.commediabistro.comGraphics.com

    Search:

    Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

    Jupitermedia Corporate Info


    Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

    Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers