IT Community - Software Programming, Web Development and Technical Support

Email Verification in ASP.NET

This is a discussion on Email Verification in ASP.NET within the C# Programming forums, part of the Software Development category; Email Verification in ASP.NET E-Mail Verification using c#.net Goals: This project is used to verify the e-...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C# Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 07-17-2007, 12:15 AM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 633
oxygen is on a distinguished road
Default Email Verification in ASP.NET

Email Verification in ASP.NET

E-Mail Verification using c#.net

Goals:

This project is used to verify the e-mail id.

Source:

In the aspx page add a button control, label and textbox.

In the aspx.cs page Button1 click event paste the following coding.

int result;
result = ChatMailServer(TextBox1.Text.Trim());

if (result == 1)
{
Label1.Text = "Valid E-mail Address";
}
if (result == 2)
{
Label1.Text = "Not a Valid E-mail Address";
}
if (result == 3)
{
Label1.Text = "Error Occured but Domain was GOOD";
}
if (result == 4)
{
Label1.Text = "Domain was invalid";
}


Then add a following functions.

public int ChatMailServer(string sEmail)
{
NetworkStream oStream;
string sFrom;
string sTo;
string sResponse;
string Remote_Addr;
string mserver;
string[] sText;
int returnvalue = 0;
sTo = "<" + sEmail + ">";
sText = sEmail.Split('@');
mserver = NSLookup(sText[1]);
if (mserver == "")
{
returnvalue = 4;
return returnvalue;

}
Remote_Addr = "sify.com";
sFrom = "<balu_bcs@" + Remote_Addr + ">";
TcpClient oConnection = new TcpClient();

try
{
oConnection.SendTimeout = 3000;
oConnection.Connect(mserver, 25);
oStream = oConnection.GetStream();
sResponse = GetData(oStream);
sResponse = TalkToServer(oStream, "HELO " + Remote_Addr + "\n");
sResponse = TalkToServer(oStream, "MAIL FROM: " + sFrom + "\n");
if (ValidResponse(sResponse))
{
sResponse = TalkToServer(oStream, "RCPT TO: " + sTo + "\n");
if (ValidResponse(sResponse))
{
returnvalue = 1;
}
else
{
returnvalue = 2;
}
}
TalkToServer(oStream, "QUIT" + "\n");
oConnection.Close();
oStream = null;
}
catch
{
returnvalue = 3;
}

return returnvalue;
}
private string GetData(NetworkStream oStream)
{
byte[] bResponse = new byte[1024];
string sResponse = "";
int lenStream = 0;

lenStream = oStream.Read(bResponse, 0, 1024); // Doubt

if (lenStream > 0)
{
sResponse = Encoding.ASCII.GetString(bResponse, 0, 1024);
}
return sResponse;

}
private string SendData(NetworkStream oStream, string sToSend)
{
string sResponse;
byte[] bArray = Encoding.ASCII.GetBytes(sToSend.ToCharArray());

oStream.Write(bArray, 0, bArray.Length);
sResponse = GetData(oStream);

return sResponse;
}
private bool ValidResponse(string sResult)
{
bool bResult = false;
int iFirst;

if (sResult.Length > 1)
{
iFirst = Convert.ToInt32(sResult.Substring(0, 1));
if (iFirst < 3)
{
bResult = true;
}

}

return bResult;
}
private string TalkToServer(NetworkStream oStream, string sToSend)
{
string sresponse;

sresponse = SendData(oStream, sToSend);

return sresponse;
}
private string NSLookup(string sDomain)
{
ProcessStartInfo info = new ProcessStartInfo();
info.UseShellExecute = false;
info.RedirectStandardInput = true;
info.RedirectStandardOutput = true;
info.FileName = "nslookup";
info.Arguments = "-type=MX " + sDomain.ToUpper().Trim();

Process ns;
ns = Process.Start(info);
StreamReader sout;
sout = ns.StandardOutput;
Regex reg = new Regex("mail exchanger = (?<server>[^\\\\\\s]+)");
string mailserver = "";
string response = "";
do
{
response = sout.ReadLine();
Match amatch = reg.Match(response);
Debug.WriteLine(response);
if (amatch.Success)
{
mailserver = amatch.Groups["server"].Value;
}
} while (sout.Peek() > -1);

return mailserver;

}
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 09-07-2007, 08:44 AM
S.Vinothkumar S.Vinothkumar is offline
D-Web Genius
 
Join Date: May 2007
Posts: 1,061
S.Vinothkumar is on a distinguished road
Wink Re: Email Verification in ASP.NET

Hi buddies,

We can use the regular expression for email validation as follows .....

Code:
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtEmail"
                ErrorMessage="Invalid Email Id" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
                Width="113px" Display="Dynamic" Font-Size="Smaller"></asp:RegularExpressionValidator>
__________________
S.VinothkumaR
Behind me is infinite power,
Before me is Endless Possibility,
Around me is Boundless Opportunity,
Why should I fear!
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP:Tutorial - Email Verification pranky PHP Programming 2 10-05-2008 11:19 PM
Formal verification method Shanthi Software Testing 0 01-14-2008 04:31 AM
What is the verification testing Strategies? sundarraja Software Testing 2 01-14-2008 03:23 AM
What is verification? validation? devarajan.v Software Testing 2 07-17-2007 07:56 AM
Verification & Validation vadivelanvaidyanathan Quality Engineering and Methodologies 0 04-18-2007 04:06 AM


All times are GMT -7. The time now is 04:50 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0