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..
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.
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;
}
}
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.
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.