C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Email »

Easy Way to send mail through ASP.Net & C#.Net


Posted Date: 29 May 2009    Resource Type: Code Snippets    Category: Email
Author: Manoranjan SahooMember Level: Gold    
Rating: 1 out of 5Points: 10



You can use the following code to send mail.


using System.Net.Mail;
using System.Configuration;

public int SendMessage(string subject, string messageBody,string fromAddress, string toAddress)
{
MailMessage message = new MailMessage();
message.IsBodyHtml = true;
SmtpClient client = new SmtpClient();
message.From = new MailAddress(fromAddress.ToString ());
if (toAddress.Trim().Length > 0)
{
foreach (string addr in toAddress.Split(';'))//you can use any delimiter
{
message.To.Add(new MailAddress(addr));
}
}
message.Subject = subject;
message.Body = messageBody;
client.Host = "SMTPServerName";
client.Send(message);
return 1;
}


You can send message with this code.



Responses

Author: Danasegarane.A    01 Jun 2009Member Level: Diamond   Points : 1
There is no need to separate the mail address. Just pass the mail address separated by ;





Author: Manoranjan Sahoo    01 Jun 2009Member Level: Gold   Points : 1
Yes you are right, but in that case all addresses are showing on the all recipient's mail.



Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
SmtpClient  .  Email Sending  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Sending an e-mail
Previous Resource: Sending Email to multiple users using VB.net
Return to Discussion Resource Index
Post New Resource
Category: Email


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use