Please support our C# advertiser: Programming Forums
Views: 17867 | Replies: 3
![]() |
•
•
Join Date: Jul 2005
Posts: 7
Reputation:
Rep Power: 0
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
•
•
Join Date: Jul 2005
Location: Kansas City, Missouri
Posts: 17
Reputation:
Rep Power: 4
Solved Threads: 3
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.
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
•
•
Join Date: Jul 2005
Location: Kansas City, Missouri
Posts: 17
Reputation:
Rep Power: 4
Solved Threads: 3
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);
•
•
Join Date: Aug 2008
Posts: 1
Reputation:
Rep Power: 0
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
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
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)





Linear Mode