| | |
Need Email validation source code (C#)
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2005
Posts: 7
Reputation:
Solved Threads: 0
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
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,
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.
Cheers,
Steve
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)
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
Oops. The last line should read
C# Syntax (Toggle Plain Text)
System.Web.Mail.SmtpMail.Send(to, from subject, body);
•
•
•
•
Originally Posted by cambia
C# Syntax (Toggle Plain Text)
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);
•
•
Join Date: Aug 2008
Posts: 1
Reputation:
Solved Threads: 0
•
•
•
•
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
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
![]() |
Similar Threads
- HELP : email validation (Shell Scripting)
Other Threads in the C# Forum
- Previous Thread: Inheritence question :(
- Next Thread: question about reading from/writing to a stream
| Thread Tools | Search this Thread |
Tag cloud for C#
.net access algorithm array barchart bitmap box buttons c# chat check checkbox class client color combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees draganddrop drawing encryption enum event excel file files form format forms ftp function gdi+ httpwebrequest image index input install java label list listbox listener login mandelbrot math mouseclick mysql networking object operator oracle path photoshop picturebox pixelinversion post prime programming radians regex remote remoting resource richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml





