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

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.


Comments

Author: Danasegarane.A01 Jun 2009 Member Level: Gold   Points : 1

There is no need to separate the mail address. Just pass the mail address separated by ;


Author: Manoranjan Sahoo01 Jun 2009 Member Level: Gold   Points : 1

Yes you are right, but in that case all addresses are showing on the all recipient's mail.



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: