//application-global error handler void ApplicationInstance_Error(object sender, EventArgs e) { Exception ex = Server.GetLastError(); //now here's a tricky part //pay attention //if its a TypeInitializationException it means that there was an error in some static constructor //which means that most likely user has forgot to run the database upgrade script or wrong connection string or smth similar //but even if he runs it afterwards, the exception will still "stay" there, //because TypeInitializationException is thrown only once. By the runtime. //So, let's unload/restart our app, so next time when it will be accessed - //it will RE-RUN static conctructors if (ex is TypeInitializationException) { HttpRuntime.UnloadAppDomain(); return; } if (ex == null) { return; } if (ex is ViewStateException || ex.InnerException is ViewStateException) { return; } //send error report try { string errorDescr = ex.ToString(); if (HttpContext.Current != null && HttpContext.Current.Request != null) { errorDescr = HttpContext.Current.Request.Url + "\n\n" + errorDescr + "\n\n" + HttpContext.Current.Request.UserAgent + "\n" + HttpContext.Current.Request.UserHostAddress; } SendNotifications.SendEmail(!string.IsNullOrEmpty(Settings.SendErrorReportsTo) ? Settings.SendErrorReportsTo.Split(new char[] { ';', ',' }, StringSplitOptions.RemoveEmptyEntries) : new string[] { null }, "error in the Forum application", errorDescr, async: true); } catch { } //do nothing, we failed to send an error report }
static void Main(string[] args) { SendNotifications obj = new SendNotifications(); obj.SendEmail(); }
public void TestMail() { SendNotifications obj = new SendNotifications(); obj.SendEmail(); }
private void btnSubmit_Click(object sender, EventArgs e) { var popup = new PopupNotifier(); popup.Image = Properties.Resources.email; popup.TitleText = "Email Notification"; if (ValidateChildren(ValidationConstraints.Enabled)) { var r = MetroMessageBox.Show(this, @"Are you sure you want to SUBMIT?", @"eVoting System", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (r == DialogResult.Yes) { Cursor.Current = Cursors.WaitCursor; using (_cnn = new SqlConnection(Properties.Settings.Default.DbConn)) { _cnn.Open(); if (CheckVoter()) { var k = Verify(_mRegMin1, _mRegMin2, _mRegMin3); if (k == -1) { using (_cmd = new SqlCommand("spAddVoter", _cnn)) { _cmd.CommandType = CommandType.StoredProcedure; _cmd.Parameters.AddWithValue("@voterPin", voterPin); _cmd.Parameters.AddWithValue("@firstName", txtFirstname.Text); _cmd.Parameters.AddWithValue("@lastName", txtLastname.Text); _cmd.Parameters.AddWithValue("@gender", cmbGender.Text); _cmd.Parameters.AddWithValue("@phoneNumber", txtPhoneNumber.Text); _cmd.Parameters.AddWithValue("@email", txtEmail.Text); _cmd.Parameters.AddWithValue("m_reg1", _mRegMin1); _cmd.Parameters.AddWithValue("m_reg2", _mRegMin2); _cmd.Parameters.AddWithValue("m_reg3", _mRegMin3); var outParameter = new SqlParameter(); outParameter.ParameterName = "@voterId"; outParameter.SqlDbType = SqlDbType.UniqueIdentifier; outParameter.Direction = ParameterDirection.Output; _cmd.Parameters.Add(outParameter); var ms = new MemoryStream(); picImage.Image.Save(ms, ImageFormat.Bmp); byte[] data = ms.ToArray(); _cmd.Parameters.AddWithValue("@pic", data); try { _cmd.ExecuteNonQuery(); voterId = outParameter.Value.ToString(); var body = string.Format( "Hi, you are registered successfully. " + Environment.NewLine + "Your Security Key is {0}. Your Voter ID is {1}", voterId, voterPin); var emailReply = SendNotifications.SendEmail(txtEmail.Text, body); if (emailReply != null) { popup.ContentText = emailReply; } MetroMessageBox.Show(this, @"Data Submitted Successfully!", @"eVoting System", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); ClearAll(); popup.Popup(); } catch (SqlException ex) { MetroMessageBox.Show(this, @"Data unable to save due to " + ex.Message); } } } else { MetroMessageBox.Show(this, @"You have registered before", @"eVoting System", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); _mFpm.EnableAutoOnEvent(false, 0); } } else { MetroMessageBox.Show(this, @"Fingerprint does no match", @"eVoting System", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); } } Cursor.Current = Cursors.Default; } } }