Monday, 10 June 2013

How to send email from asp.net

How to send a mail private void button1_Click(object sender, EventArgs e) { if (_Emaild != null) { string _tomail = _Emaild; MailMessage mail = new MailMessage(); mail.To.Add(_tomail); mail.From = new MailAddress("suresh.jaglan2@gmail.com"); mail.Subject = txt_subject.Text; mail.Body = txt_contents.Text; mail.IsBodyHtml = true; SmtpClient smtp = new SmtpClient("localhost", 25); smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address smtp.Credentials = new System.Net.NetworkCredential ("suresh.jaglan2@gmail.com", "Password"); smtp.DeliveryMethod = SmtpDeliveryMethod.Network; smtp.EnableSsl = true; smtp.Send(mail); MessageBox.Show("Email Send Succfully"); } else { MessageBox.Show("Please enter Email-ID"); } }

No comments:

Post a Comment