Hi.....
use this code....
private void Mail_sen()
{
try
{
string bBody = mailmsg();
string email = TextBox4.Text;
string sSub = "Contact_Us";
SendMailmsg(bBody, email, email, email, sSub, "sendcc");
}
catch (Exception ex)
{
}
}
private string mailmsg()
{
StringBuilder strHTML = new StringBuilder();
strHTML.Append("<table width="70%">");
strHTML.Append("<tr><td width="100%" colspan="2"><b>Dear abc </b></td></tr>");
strHTML.Append("<tr bgcolor="cayn"><center><table><tbody><tr><td width="100%" colspan="2">CONTACT </td></tr></tbody></table></center></tr>");
strHTML.Append("<tr><td width="20%"><b>Name : </b></td><td width="80%">abc</td></tr>");
strHTML.Append("<tr><td width="20%"><b>Email ID : </b></td><td width="80%">abc@gmail.com</td></tr>");
strHTML.Append("<tr><td width="20%"><b>Phone No : </b></td><td width="80%">999999999</td></tr>");
strHTML.Append("<tr><td width="20%"><b>Comments : </b></td><td width="80%">hi this code try</td></tr>");
strHTML.Append("</table>");
return strHTML.ToString();
}
public static string SendMailmsg(string body, string msgto, string cc, string msgfrom, string sub, string cond)
{
string status = "fail";
try
{
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
message.Body = body;
message.IsBodyHtml = true;
if (cond == "notsendcc")
{
message.To.Add(msgto);
}
if (cond == "sendcc")
{
message.To.Add(msgto);
message.CC.Add(cc);
}
message.From = new System.Net.Mail.MailAddress(msgfrom);
message.Subject = sub;
message.Priority = System.Net.Mail.MailPriority.High;
SmtpClient SmtpMail = new SmtpClient();
{
SmtpMail.Host = "smtp.gmail.com";
SmtpMail.Port = 587;
SmtpMail.EnableSsl = true;
SmtpMail.UseDefaultCredentials = true;
SmtpMail.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
SmtpMail.Credentials = new System.Net.NetworkCredential("email_id", "pass******");
SmtpMail.Send(message);
}
message = null;
status = "success";
}
catch (Exception ex)
{
throw (ex);
}
return status;
}