943,020 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 46489
  • C# RSS
Jul 23rd, 2005
-1

Need Email validation source code (C#)

Expand Post »
Hi,

I am working on a Desktop application using C# .NET

Looking for some code that does 'email syntax validation' and 'send mail' tasks.
Since it is not a web based application this cannot be done using Web based namespaces etc.


Can anyone please help me out or even suggest sumthing..

Thanx
- Prasadd
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Prasadd is offline Offline
7 posts
since Jul 2005
Jul 28th, 2005
0

Re: Need Email validation source code (C#)

Hi Prasadd,

1) First the email syntax validation.

I have written an article on this at the following link. In short, you can use regular expressions:
Email Validation

2) Send email from a desktop application.

You can use the SmtpMail class just as you would in an ASP.NET application. You just need to add a reference to the System.Web.dll library. If you are using Visual Studio .NET, go to the Solution Explorer and right click 'References' in your project. Choose to Add Reference. Then browse the .NET tab for System.Web.dll and add it. Then the following should work.

C# Syntax (Toggle Plain Text)
  1. System.Web.Mail.SmtpMail.SmtpServer = "your server";
  2. string to = "you@email.com";
  3. string from = "someone@email.com";
  4. string subject = "Email Test";
  5. string body = "Test Body";
  6. Sysetm.Web.Mail.SmtpMail.SmtpServer.Send(to, from subject, body);

Cheers,
Steve
Reputation Points: 10
Solved Threads: 3
Newbie Poster
cambia is offline Offline
17 posts
since Jul 2005
Jul 28th, 2005
0

Re: Need Email validation source code (C#)

Oops. The last line should read
C# Syntax (Toggle Plain Text)
  1. System.Web.Mail.SmtpMail.Send(to, from subject, body);

Quote originally posted by cambia ...
C# Syntax (Toggle Plain Text)
  1. System.Web.Mail.SmtpMail.SmtpServer = "your server";
  2. string to = "you@email.com";
  3. string from = "someone@email.com";
  4. string subject = "Email Test";
  5. string body = "Test Body";
  6. Sysetm.Web.Mail.SmtpMail.SmtpServer.Send(to, from subject, body);
Reputation Points: 10
Solved Threads: 3
Newbie Poster
cambia is offline Offline
17 posts
since Jul 2005
Aug 30th, 2008
0

Re: Need Email validation source code (C#)

Click to Expand / Collapse  Quote originally posted by Prasadd ...
Hi,

I am working on a Desktop application using C# .NET

Looking for some code that does 'email syntax validation' and 'send mail' tasks.
Since it is not a web based application this cannot be done using Web based namespaces etc.


Can anyone please help me out or even suggest sumthing..

Thanx
- Prasadd
hi, Prasadd

Use RegularExpression.RegEx class
here is example for Email validation that i have made try it.

public static bool ValidEmail(string validatingstring, string displaymessage)
{
if (!Regex.Match(validatingstring, @"^[a-zA-Z][a-zA-Z0-9_-]+@[a-zA-Z]+[.]{1}[a-
zA-Z]+$").Success)
{
//Email was incorrect
ErrorMessage(displaymessage);
return false;
}
else
{
return true;
}
}

Regards,
Chirag Shah
Reputation Points: 10
Solved Threads: 0
Newbie Poster
chirag.3g is offline Offline
1 posts
since Aug 2008
May 22nd, 2010
0

Validate Email in C#

I'm not satisfied with your example...
To validate Email id in c#

using System.Text.RegularExpressions;

Coding:

if (!Regex.Match(textBox1.Text, @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*").Success)
MessageBox.Show(textBox1.Text+" is Invalid Email");
else
MessageBox.Show(textBox1.Text+" is valid Email");
Last edited by joinwithchakra; May 22nd, 2010 at 5:39 am.
Reputation Points: 9
Solved Threads: 0
Newbie Poster
joinwithchakra is offline Offline
2 posts
since May 2010
May 22nd, 2010
-1

Validate Email in C#

I'm not satisfied with your example...
To validate Email id in c#

using System.Text.RegularExpressions;

Coding:

if (Regex.Match(textBox1.Text, @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*").Success)
MessageBox.Show("valid Email");
else
MessageBox.Show("Invalid Email");

Chakrapani,
Hyderabad
Last edited by joinwithchakra; May 22nd, 2010 at 5:41 am.
Reputation Points: 9
Solved Threads: 0
Newbie Poster
joinwithchakra is offline Offline
2 posts
since May 2010
Nov 2nd, 2010
0
Re: Need Email validation source code (C#)
string strRegex = @"^([a-zA-Z0-9\.]+)@(|yahoo|gmail|).(|com|in|edu|info|gov|int|mil|net|org|biz|name|museum|coop|aero|pro|tv|)$";
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Babitha.p is offline Offline
1 posts
since Nov 2010
Nov 2nd, 2010
0
Re: Need Email validation source code (C#)
**Thread Locked**
Moderator
Reputation Points: 2134
Solved Threads: 1227
Posting Genius
adatapost is offline Offline
6,524 posts
since Oct 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
This thread is currently closed and is not accepting any new replies.
Previous Thread in C# Forum Timeline: TCP Client / TCP Sever Help
Next Thread in C# Forum Timeline: Alternate Of Activex





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC