An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
program:-
Expand|Select|Wrap|Line Numbers
- using System;
- using System.Configuration;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Net.Security;
- using System.Net.Mail;
- using System.Net;
- namespace WebDesign
- {
- public partial class contact_us : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- protected void SendMail()
- {
- // any address where the email will be sending
- var toAddress = YourEmail.Text.ToString();
- // Gmail Address from where you send the mail
- var fromAddress = "..fill..";
- //Password of your gmail address
- const string fromPassword = "..fill...";
- // Passing the values and make a email formate to display
- string subject = YourSubject.Text.ToString();
- string body = "From: " + YourName.Text + "\n";
- body += "Email: " + YourEmail.Text + "\n";
- body += "Subject: " + YourSubject.Text + "\n";
- body += "Question: \n" + Comments.Text + "\n";
- // smtp settings
- var smtp = new System.Net.Mail.SmtpClient();
- {
- smtp.Host = "smtp.gmail.com";
- smtp.Port = 587;
- smtp.EnableSsl = true;
- smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
- smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
- smtp.Timeout = 20000;
- }
- // Passing values to smtp object
- smtp.Send(toAddress, fromAddress, subject, body);
- }
- protected void btnSubmit_Click(object sender, EventArgs e)
- {
- try
- {
- //here on button click what will done
- SendMail();
- DisplayMessage.Text = "mail send";
- DisplayMessage.Visible = true;
- YourSubject.Text = "";
- YourEmail.Text = "";
- YourName.Text = "";
- Comments.Text = "";
- }
- catch (Exception) { }
- }
- }
- }