private void _smptpClient_SendCompleted(object sender, AsyncCompletedEventArgs e) { if (e.Error != null) { try { VCM_Mail _vcmMail = new VCM_Mail(-1); _vcmMail.From = System.Configuration.ConfigurationManager.AppSettings["FromEmail"].ToString(); _vcmMail.To = System.Configuration.ConfigurationManager.AppSettings["FromEmail"].ToString(); _vcmMail.SendAsync = true; _vcmMail.Subject = "Mail has not been sent " + _mailSubject; _vcmMail.Body = "<div style=\"font-size:8pt;font-family:Verdana\">Dear Broker,<br/><br/> Mail has not been sent to " + _mailTo + " users for below session " + "<table>" + "<tr><td style=\"FONT-SIZE: 8pt; FONT-FAMILY: Verdana;\">" + _mailSubject + " </td></tr>" + "<tr><td style=\"FONT-SIZE: 8pt; FONT-FAMILY: Verdana;\">SYSTEM RUNNING ON : " + System.Configuration.ConfigurationManager.AppSettings["SystemRunningOn"].ToUpper() + " </td></tr>" + "<tr><td style=\"FONT-SIZE: 8pt; FONT-FAMILY: Verdana;\">ERROR MESSAGE : " + e.Error.Message + " </td></tr>" + "<tr><td style=\"FONT-SIZE: 8pt; FONT-FAMILY: Verdana;\">ERROR INNEREXCEPTION : " + e.Error.InnerException + " </td></tr>" + "<tr><td style=\"FONT-SIZE: 8pt; FONT-FAMILY: Verdana;\">ERROR STAKETRACE : " + e.Error.StackTrace + " </td></tr>" + "<tr><td> </br></br> </td></tr>" + "<tr><td style=\"FONT-SIZE: 8pt; FONT-FAMILY: Verdana;\">--Mail Signature--</td></tr>" + "</table> " + "<br/><br/> "; _vcmMail.IsBodyHtml = true; _vcmMail.SendMail(); _vcmMail = null; LogUtility.Error("VCM_Mail.cs", "_smptpClient_SendCompleted()", e.Error.Message, e.Error); } catch (Exception ex) { LogUtility.Error("VCM_Mail.cs", "_smptpClient_SendCompleted()", ex.Message, ex); } } else if (e.Cancelled) { LogUtility.Info("VCM_Mail.cs", "_smptpClient_SendCompleted()", "The asynchronous operation has been cancelled."); } }
protected void btnSendMail_Click(object sender, EventArgs e) { try { string strCC = txtTo.Text; string strSubject = txtSubject.Text; string strBody = txtBody.Text; string strIpAddress = ""; if (HttpContext.Current.Request.Headers["X-Forwarded-For"] != null) { //HttpContext.Current.Request.Headers["X-Forwarded-For"].Split(new char[] { ',' }).FirstOrDefault(); strIpAddress = "<br/><br/>[#] Attrib:X-Forwarded-For - found / ELB=true <br/>[#] Ip Address = " + HttpContext.Current.Request.Headers["X-Forwarded-For"].Split(',')[0]; } else { string strHostName = ""; strHostName = System.Net.Dns.GetHostName(); IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName); IPAddress[] addr = ipEntry.AddressList; //strIpAddress = "<br/><br/>[#] Attrib:X-Forwarded-For - NOT found / ELB=false <br/>[#] Ip Address = " + addr[1].ToString(); strIpAddress = Request.UserHostAddress; } strBody += strIpAddress; string strFrom = string.IsNullOrEmpty(txtFrom.Text.Trim()) ? System.Configuration.ConfigurationManager.AppSettings["FromEmail"].ToString() : txtFrom.Text; string strTo = string.IsNullOrEmpty(txtTo.Text.Trim()) ? System.Configuration.ConfigurationManager.AppSettings["ToEmail"].ToString() : txtTo.Text; VCM_Mail objMail = new VCM_Mail(ddlSmtpServers.SelectedIndex); objMail.From = strFrom; objMail.To = strTo; objMail.Subject = strSubject; objMail.Body = strBody; objMail.IsBodyHtml = true; objMail.SendAsync = true; objMail.SendMail(); lblMessage.Text = "Mail sent"; lblMessage.ForeColor = System.Drawing.Color.Green; } catch (Exception ex) { lblMessage.Text = ex.Message + "<br/>"; if (ex.InnerException != null) { lblMessage.Text += ex.InnerException.Message + "<br/>"; if (ex.InnerException.InnerException != null) { lblMessage.Text += ex.InnerException.InnerException.Message; } } lblMessage.ForeColor = System.Drawing.Color.Red; //throw; } }
private void _smptpClient_SendCompleted(object sender, AsyncCompletedEventArgs e) { if (e.Error != null) { try { VCM_Mail _vcmMail = new VCM_Mail(-1); _vcmMail.From = System.Configuration.ConfigurationManager.AppSettings["FromEmail"].ToString(); _vcmMail.To = System.Configuration.ConfigurationManager.AppSettings["FromEmail"].ToString(); _vcmMail.SendAsync = true; _vcmMail.Subject = "Mail has not been sent " + _mailSubject; _vcmMail.Body = "<div style=\"font-size:8pt;font-family:Verdana\">Dear Broker,<br/><br/> Mail has not been sent to " + _mailTo + " users for below session " + "<table>"+ "<tr><td style=\"FONT-SIZE: 8pt; FONT-FAMILY: Verdana;\">" + _mailSubject + " </td></tr>"+ "<tr><td style=\"FONT-SIZE: 8pt; FONT-FAMILY: Verdana;\">SYSTEM RUNNING ON : " + System.Configuration.ConfigurationManager.AppSettings["SystemRunningOn"].ToUpper() + " </td></tr>" + "<tr><td style=\"FONT-SIZE: 8pt; FONT-FAMILY: Verdana;\">ERROR MESSAGE : " + e.Error.Message + " </td></tr>"+ "<tr><td style=\"FONT-SIZE: 8pt; FONT-FAMILY: Verdana;\">ERROR INNEREXCEPTION : " + e.Error.InnerException + " </td></tr>"+ "<tr><td style=\"FONT-SIZE: 8pt; FONT-FAMILY: Verdana;\">ERROR STAKETRACE : " + e.Error.StackTrace + " </td></tr>"+ "<tr><td> </br></br> </td></tr>"+ "<tr><td style=\"FONT-SIZE: 8pt; FONT-FAMILY: Verdana;\">--Mail Signature--</td></tr>"+ "</table> " + "<br/><br/> "; _vcmMail.IsBodyHtml = true; _vcmMail.SendMail(); _vcmMail = null; LogUtility.Error("VCM_Mail.cs", "_smptpClient_SendCompleted()", e.Error.Message, e.Error); } catch (Exception ex) { LogUtility.Error("VCM_Mail.cs", "_smptpClient_SendCompleted()", ex.Message, ex); } } else if (e.Cancelled) { LogUtility.Info("VCM_Mail.cs", "_smptpClient_SendCompleted()", "The asynchronous operation has been cancelled."); } }