Saturday, April 28, 2007

Sending Mail Using System.Net.Mail

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).




No comments:

Creative Commons License
Disclaimers:We have tried hard to provide accurate information, as a user, you agree that you bear sole responsibility for your own decisions to use any programs, documents, source code, tips, articles or any other information provided on this Blog.