MailMessage Mail = new MailMessage();
MailAddress ma = new MailAddress(txtFrom.Text,txtName.Text);
Mail.From = ma;
Mail.To.Add(txtTo.Text);
if(txtCC.Text.Trim().Length != 0)
Mail.CC.Add(txtCC.Text);
if(txtBCC.Text.Trim().Length != 0)
Mail.Bcc.Add(txtBCC.Text);
Mail.Subject = txtSubject.Text;
Mail.Body = txtComment.Text;
try
{
SmtpClient smtpMailObj = new SmtpClient();
//eg:localhost, 192.168.0.x, replace with your server name
smtpMailObj.Host = "myMailServer";
smtpMailObj.Send(Mail);
Response.Write("Your Message has been sent successfully");
}
catch (Exception ex)
{
Response.Write("Message Delivery Fails");
}
No comments:
Post a Comment