0% found this document useful (0 votes)
54 views4 pages

Using Using Using Using Using Using Using Using Using Using Using Using Using Using Public Partial Class

This document contains code for sending an email using C# and .NET. It defines variables for the email sender and password, creates a MailMessage object, sets the to, from, subject and body properties, and uses a SmtpClient to send the email through Gmail's SMTP server on port 587, using SSL and the sender's credentials. On success, it displays a message that the email was sent.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views4 pages

Using Using Using Using Using Using Using Using Using Using Using Using Using Using Public Partial Class

This document contains code for sending an email using C# and .NET. It defines variables for the email sender and password, creates a MailMessage object, sets the to, from, subject and body properties, and uses a SmtpClient to send the email through Gmail's SMTP server on port 587, using SSL and the sender's credentials. On success, it displays a message that the email was sent.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.

Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Data.SqlClient; using System.Net.Mail; public partial class email : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { lblM11.Text = Session["password"].ToString(); } protected void Button1_Click(object sender, EventArgs e)

{ try { String Mailfrom="shuchisrivastava11@gmail. com"; String Password = "suchi9938"; using (MailMessage mail = new MailMessage()) { mail.To.Clear(); mail.To.Add(new System.Net.Mail.MailAddress(txtTo.T ext)); mail.IsBodyHtml = true; mail.From = new System.Net.Mail.MailAddress(Mailfro m); mail.Subject = txtSub.Text; mail.Body = txtMsg4.Text; System.Net.Mail.SmtpClient smtpClnt = new

System.Net.Mail.SmtpClient("smtp.gm ail.com", 587); smtpClnt.UseDefaultCredentials = false; smtpClnt.EnableSsl = true; smtpClnt.Credentials = new System.Net.NetworkCredential(Mailfr om, Password); smtpClnt.Timeout = int.MaxValue; smtpClnt.Send(mail); // return 1; lblMsg5.Text = "Send"; } } catch (Exception ex) { } } }

You might also like