Saturday, April 28, 2007

Sending Mail Using System.Net.Mail

protected void btSend_Click(object sender, EventArgs e)
MailMessage mM = new MailMessage();
mM.From = new MailAddress(txtFrom.Text);
mM.Subject = txtSub.Text;
mM.Body = txtMsg.Text;
mM.IsBodyHtml = true;
mM.Priority = MailPriority.High;
//SmtpClient sC = new SmtpClient("");
SmtpClient sC = new SmtpClient("");
sC.Port = 587;
//sC.Credentials = new NetworkCredential("Y! UserId", "Y! Pwd");
sC.Credentials = new NetworkCredential("Gmail UserId", "Gmail Pwd");
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.