Note: This is not the complete source code--just the main source file.
You can download the full source (with include files) from our sample code archive by clicking on the diskette icons.
// SimpleEmailValidation sample
// version 2002-09-01
//
// Demonstrates basic email address validation with HexValidEmail.
//
// History:
// 2002-09-01 Created
//
// Copyright 2002 Hexillion Technologies. All rights reserved.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND/OR
// FITNESS FOR A PARTICULAR PURPOSE.
#include "stdafx.h"
#include <iostream>
#include "HexComPtr.h"
#include "HexValidEmail.h"
#import "HexValidEmail.dll" no_namespace
using namespace std;
int main(int argc, char* argv[])
{
int iReturn = 0;
try
{
// If we don't have one argument (aside from utility name)...
if( 2 != argc )
{
// Display usage and exit
cout << "Usage: SimpleEmailValidation emailAddress" << endl;
throw 0;
}
CoInitialize( NULL );
// Declare instance of a licensing-aware _com_ptr_t derivative
HexComPtr< HEX_IIID( IConnectionSync ) > pVE;
// Use this code to get your runtime license key while your license
// file is in place. Then comment the code out and put the runtime
// key in the CreateInstanceLic call below. Your binary will then
// work without the license file.
// _bstr_t bstrKey;
// pVE.RequestLicKey( __uuidof( Connection ), bstrKey );
// cout << "Runtime license key: " << (TCHAR*)bstrKey << endl;
// Create an instance of HexValidEmail.Connection
HRESULT hr = pVE.CreateInstanceLic( __uuidof( Connection ), L"*** Put your runtime license key here ***" );
// If CreateInstance failed...
if( FAILED( hr ) )
{
cout << "Creation of HexValidEmail.Connection instance failed. HRESULT=0x" << hex << hr << endl;
throw -1;
}
// You know you're using the runtime license when the Error property and
// LicensedProcessors property are both zero
bool bUsingRuntimeKey = (0 == pVE->Error) && (0 == pVE->LicensedProcessors);
// Identify yourself for SMTP (use your own information here)
// See http://www.hexillion.com/docs/guides/HexValidEmail/concepts/polite_usage.htm
pVE->FromDomain = "hexillion.com"; // The domain name of your machine
pVE->FromEmail = "HexValidEmail@hexillion.com"; // Email address of technical contact person
// Set timeouts (optional)
pVE->Timeouts->Item( hexVeTimeoutDnsTotal )->Value = 4000; // 4 seconds
pVE->Timeouts->Item( hexVeTimeoutSmtpTotal )->Value = 10000; // 10 seconds
// Do the validation to SMTP level
int iRating = pVE->Validate( argv[1], hexVeLevelSmtp );
// If the address is definitely bad...
if( hexVeLevelBad == iRating )
// Display the reason why
cout << "Bad address: " << (TCHAR*)GetVeErrorString( pVE->Error ) << endl;
// If validation didn't reach intended level...
else if( iRating < hexVeLevelSmtp )
// Say why
cout << "No problems were found with the address, but the validation failed at level "
<< (iRating + 1) << endl
<< "with the following error: " << (TCHAR*)GetVeErrorString( pVE->Error ) << endl;
else
// No problems encountered
cout << "No problems were found with the address. " << endl
<< "That does not guarantee it is good." << endl;
}
catch( int i )
{
iReturn = i;
}
CoUninitialize();
return iReturn;
}