RSS Forums RSS
Please support our C# advertiser: Programming Forums
Views: 17867 | Replies: 3
Reply
Join Date: Jul 2005
Posts: 7
Reputation: Prasadd is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Prasadd Prasadd is offline Offline
Newbie Poster

Help Need Email validation source code (C#)

  #1  
Jul 23rd, 2005
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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2005
Location: Kansas City, Missouri
Posts: 17
Reputation: cambia is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 3
cambia's Avatar
cambia cambia is offline Offline
Newbie Poster

Re: Need Email validation source code (C#)

  #2  
Jul 28th, 2005
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.

System.Web.Mail.SmtpMail.SmtpServer = "your server";
string to = "you@email.com";
string from = "someone@email.com";
string subject = "Email Test";
string body = "Test Body";
Sysetm.Web.Mail.SmtpMail.SmtpServer.Send(to, from subject, body);

Cheers,
Steve
Reply With Quote  
Join Date: Jul 2005
Location: Kansas City, Missouri
Posts: 17
Reputation: cambia is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 3
cambia's Avatar
cambia cambia is offline Offline
Newbie Poster

Re: Need Email validation source code (C#)

  #3  
Jul 28th, 2005
Oops. The last line should read
System.Web.Mail.SmtpMail.Send(to, from subject, body);

Originally Posted by cambia
System.Web.Mail.SmtpMail.SmtpServer = "your server";
string to = "you@email.com";
string from = "someone@email.com";
string subject = "Email Test";
string body = "Test Body";
Sysetm.Web.Mail.SmtpMail.SmtpServer.Send(to, from subject, body);
Reply With Quote  
Join Date: Aug 2008
Posts: 1
Reputation: chirag.3g is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
chirag.3g chirag.3g is offline Offline
Newbie Poster

Re: Need Email validation source code (C#)

  #4  
Aug 30th, 2008
Originally Posted by Prasadd View 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


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
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 12:13 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC