public void Check() { try { var req = WebRequest.Create(CheckUri); var res = req.GetResponse(); var stream = res.GetResponseStream(); var sr = new StreamReader(stream); var body = sr.ReadToEnd(); sr.Close(); stream.Close(); var matches = _ipPattern.Matches(body); // Send these IP address matches in an email to me. var msgBody = new StringBuilder(); msgBody.AppendLine("IP Addresses:"); foreach (var match in matches) { msgBody.AppendLine(match.ToString()); } var msg = new MailMessage(EmailFrom.ToString(), EmailTo.ToString(), EmailSubject, msgBody.ToString()); var smtp = new SmtpClient(); smtp.Send(msg); } catch (Exception ex) { EventLog.WriteEntry(Assembly.GetExecutingAssembly().FullName, string.Format("{0}\n\n{1}", ex.Message, ex.StackTrace), EventLogEntryType.Error); } }
protected void Button1_Click(object sender, EventArgs e) { DataView dvieww; string SMTP; string BCC; string EmailFrom; string Password; dvieww = (DataView)SqlDataSource8.Select(DataSourceSelectArguments.Empty); SMTP = (string)dvieww.Table.Rows[0]["SMTP"]; BCC = (string)dvieww.Table.Rows[0]["BCC"]; EmailFrom = (string)dvieww.Table.Rows[0]["EmailFrom"]; Password = (string)dvieww.Table.Rows[0]["Password"]; MailMessage mail = new MailMessage(); SmtpClient SmtpServer = new SmtpClient(SMTP.ToString()); mail.From = new MailAddress(EmailFrom.ToString()); //Email acpe = new Email(); mail.To.Add(TextBox2.Text); mail.Bcc.Add(BCC.ToString()); StreamReader reader = new StreamReader(Server.MapPath("~/email/Contact.html")); string readFile = reader.ReadToEnd(); string myString = ""; myString = readFile; //string name = HttpUtility.UrlEncode(Encrypt(Session["UserName"].ToString().Trim())); //string technology = HttpUtility.UrlEncode(Encrypt(ddlTechnology.SelectedItem.Value)); myString = myString.Replace("{#Name}", TextBox1.Text); myString = myString.Replace("{#Email}", TextBox2.Text); myString = myString.Replace("{#Message}", TextBox3.Text); //myString = myString.Replace("{#message}", TextBox4.Text); mail.Subject = "New Contact on onlinehcs.com"; mail.IsBodyHtml = true; mail.Body = myString.ToString(); SmtpServer.Port = 8889; SmtpServer.Credentials = new System.Net.NetworkCredential(EmailFrom.ToString(), Password.ToString()); SmtpServer.EnableSsl = false; object userState = mail; SmtpServer.SendCompleted += new SendCompletedEventHandler(SMTPClientForAsy.SmtpClient_OnCompleted); SmtpServer.SendAsync(mail, userState); TextBox1.Text = string.Empty; TextBox2.Text = string.Empty; TextBox3.Text = string.Empty; Label5.Text = "Submitted Successfully"; }