protected void btSend_Click(object sender, EventArgs e)
{
try
{
MailMessage mM = new MailMessage();
mM.From = new MailAddress(txtFrom.Text);
mM.To.Add(txtTo.Text);
mM.Subject = txtSub.Text;
mM.Body = txtMsg.Text;
mM.IsBodyHtml = true;
mM.Priority = MailPriority.High;
//SmtpClient sC = new SmtpClient("smtp.mail.yahoo.com");
SmtpClient sC = new SmtpClient("smtp.gmail.com");
sC.Port = 587;
//sC.Credentials = new NetworkCredential("Y! UserId", "Y! Pwd");
sC.Credentials = new NetworkCredential("Gmail UserId", "Gmail Pwd");
sC.Send(mM);
lbReport.Text = "Mail Send Successfully";
lbReport.ForeColor = Color.Green;
}
catch(Exception ex)
{
lbReport.Text = ex+"Mail Sending Fail's";
lbReport.ForeColor = Color.Red;
}
}
Controls Used & Id's
Text Box = txtFrom, txtTo, txtSub, txtMsg.
Button = btSend.
Label = lbReport.(For Mail Status).
Saturday, April 28, 2007
Sending Mail Using System.Net.Mail
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment