protected From_Data getFormData() { From_Data frmdt = new From_Data(); frmdt.referredby = (tbReferredBy.Text.Length > 0) ? tbReferredBy.Text : null; frmdt.program = (ddlProgram.Text.Length > 0) ? ddlProgram.Text : null; frmdt.businessname = (tbBusinessName.Text.Length > 0) ? tbBusinessName.Text : null; frmdt.businesstype = (tbBusinessType.Text.Length > 0) ? tbBusinessType.Text : null; frmdt.contactname = (tbContactName.Text.Length > 0) ? tbContactName.Text : null; frmdt.phonenumber = (tbPhoneNumber.Text.Length > 0) ? tbPhoneNumber.Text : null; frmdt.emailaddress = (tbEmailAddress.Text.Length > 0) ? tbEmailAddress.Text : null; frmdt.creditcards = (ddlCreditCards.Text.Length > 0) ? ddlCreditCards.Text : null; frmdt.salesvolume = (ddlMonthlyVolume.Text.Length > 0) ? ddlMonthlyVolume.Text : null; frmdt.averageticket = (tbAverageTicket.Text.Length > 0) ? tbAverageTicket.Text : null; frmdt.terminals = (ddlTerminal.Text.Length > 0) ? ddlTerminal.Text : null; frmdt.chargemethod = (ddlChargeMethod.Text.Length > 0) ? ddlChargeMethod.Text : null; // frmdt.statements = (afuStatements.Text.Length > 0) ? afuStatementsyarp.Text : null; return(frmdt); }
protected Int32 Send_Email_Database_Insert() { if (HttpContext.Current.Request.Cookies["quote"] != null) { // Get the Quote ID Int32.TryParse(Server.HtmlEncode(Request.Cookies["quote"]["id"]), out quoteid); } else { // Create the QUote quoteid = Create_Quote(); } if (quoteid <= 0) { return(-1); } var doinsert = false; var doexists = false; var doerror = false; var msgLog = ""; From_Data frmdt = getFormData(); var sp_status = 10002010; // Sent var sp_referredby = (frmdt.referredby != null) ? frmdt.referredby : null; var sp_program = (frmdt.program != null) ? frmdt.program : null; var sp_businessname = (frmdt.businessname != null) ? frmdt.businessname : null; var sp_businesstype = (frmdt.businesstype != null) ? frmdt.businesstype : null; var sp_contactname = (frmdt.contactname != null) ? frmdt.contactname : null; var sp_phonenumber = (frmdt.phonenumber != null) ? frmdt.phonenumber : null; var sp_emailaddress = (frmdt.emailaddress != null) ? frmdt.emailaddress : null; var sp_creditcards = (frmdt.creditcards != null) ? frmdt.creditcards : null; var sp_salesvolume = (frmdt.salesvolume != null) ? frmdt.salesvolume : null; var sp_averageticket = (frmdt.averageticket != null) ? frmdt.averageticket : null; var sp_terminals = (frmdt.terminals != null) ? frmdt.terminals : null; var sp_chargemethod = (frmdt.chargemethod != null) ? frmdt.chargemethod : null; var sp_statements = (frmdt.statements != null) ? frmdt.statements : null; #region SQL Connection using (SqlConnection con = new SqlConnection(Custom.connStr)) { Custom.Database_Open(con); #region SQL Command using (SqlCommand cmd = new SqlCommand("", con)) { #region Build cmdText String cmdText = ""; cmdText = @" UPDATE [dbo].[application_quote] SET [referredby] = @sp_referredby ,[program] = @sp_program ,[businessname] = @sp_businessname ,[businesstype] = @sp_businesstype ,[contactname] = @sp_contactname ,[phonenumber] = @sp_phonenumber ,[emailaddress] = @sp_emailaddress ,[creditcards] = @sp_creditcards ,[salesvolume] = @sp_salesvolume ,[averageticket] = @sp_averageticket ,[chargemethod] = @sp_chargemethod ,[terminals] = @sp_terminals WHERE [id] = @sp_quoteid SELECT @sp_quoteid "; #endregion Build cmdText #region SQL Parameters cmd.CommandText = cmdText; cmd.CommandType = CommandType.Text; cmd.Parameters.Clear(); cmd.Parameters.Add("@sp_quoteid", SqlDbType.Int).Value = quoteid; cmd.Parameters.Add("@sp_referredby", SqlDbType.VarChar, 100).Value = (object)sp_referredby ?? DBNull.Value; cmd.Parameters.Add("@sp_program", SqlDbType.VarChar, 250).Value = (object)sp_program ?? DBNull.Value; cmd.Parameters.Add("@sp_businessname", SqlDbType.VarChar, 250).Value = (object)sp_businessname ?? DBNull.Value; cmd.Parameters.Add("@sp_businesstype", SqlDbType.VarChar, 250).Value = (object)sp_businesstype ?? DBNull.Value; cmd.Parameters.Add("@sp_contactname", SqlDbType.VarChar, 100).Value = (object)sp_contactname ?? DBNull.Value; cmd.Parameters.Add("@sp_phonenumber", SqlDbType.VarChar, 20).Value = (object)sp_phonenumber ?? DBNull.Value; cmd.Parameters.Add("@sp_emailaddress", SqlDbType.VarChar, 100).Value = (object)sp_emailaddress ?? DBNull.Value; cmd.Parameters.Add("@sp_creditcards", SqlDbType.VarChar, 100).Value = (object)sp_creditcards ?? DBNull.Value; cmd.Parameters.Add("@sp_salesvolume", SqlDbType.VarChar, 100).Value = (object)sp_salesvolume ?? DBNull.Value; cmd.Parameters.Add("@sp_averageticket", SqlDbType.VarChar, 100).Value = (object)sp_averageticket ?? DBNull.Value; cmd.Parameters.Add("@sp_terminals", SqlDbType.VarChar, 100).Value = (object)sp_terminals ?? DBNull.Value; cmd.Parameters.Add("@sp_chargemethod", SqlDbType.VarChar, 100).Value = (object)sp_chargemethod ?? DBNull.Value; cmd.Parameters.Add("@sp_statements", SqlDbType.VarChar, 100).Value = (object)sp_statements ?? DBNull.Value; #endregion SQL Parameters // print_sql(cmd, "append"); // Will print for Admin in Local #region SQL Command Processing var chckResults = cmd.ExecuteScalar(); if (chckResults != null && chckResults.ToString() != "0") { // We inserted the ticket quoteid = Convert.ToInt32(chckResults.ToString()); // Don't show this message, it is only relevant if something went wrong //msgLog += String.Format("<li>{0}: {1}</li>", "Application Created.", sp_applicationid); doinsert = true; } else { // There was a problem inserting the ticket quoteid = -1; doerror = true; msgLog += String.Format("<li>{0}</li>", "Failed to get a Email ID."); lblProcessMessage.Text = msgLog; } #endregion SQL Command Processing } #endregion SQL Command } #endregion SQL Connection return(quoteid); }
protected Boolean Send_Email_Internal() { var emailSent = false; From_Data frmdt = getFormData(); // Standard var to1Name = System.Configuration.ConfigurationManager.AppSettings["to2Name"]; var to1Email = System.Configuration.ConfigurationManager.AppSettings["to2Email"]; var emailAddress = new MailAddress(to1Email, to1Name); var emailUser = System.Configuration.ConfigurationManager.AppSettings["mail1User"]; var emailName = System.Configuration.ConfigurationManager.AppSettings["mail1Name"]; var emailPass = System.Configuration.ConfigurationManager.AppSettings["mail1Pass"]; var senderEmail = new MailAddress(emailUser, emailName); string senderPassword = emailPass; string emailSubject = String.Format("Credit Card Processing Quote Request - {0}", quoteid); var emailFile = "Application_Quote_Internal.html"; var emailPath = "Emails/"; System.IO.StreamReader rdr = new System.IO.StreamReader(Server.MapPath(emailPath + emailFile)); var htmlBody = rdr.ReadToEnd(); rdr.Close(); rdr.Dispose(); // Convert the html Body to be dynamic with the Business Name > Client Name, etc // Also add a disclosure to the body #region Business Details htmlBody = htmlBody.Replace("{referredby}", frmdt.referredby); htmlBody = htmlBody.Replace("{program}", frmdt.program); htmlBody = htmlBody.Replace("{businessname}", frmdt.businessname); htmlBody = htmlBody.Replace("{businesstype}", frmdt.businesstype); htmlBody = htmlBody.Replace("{contactname}", frmdt.contactname); htmlBody = htmlBody.Replace("{phonenumber}", frmdt.phonenumber); htmlBody = htmlBody.Replace("{emailaddress}", frmdt.emailaddress); htmlBody = htmlBody.Replace("{creditcards}", frmdt.creditcards); htmlBody = htmlBody.Replace("{salesvolume}", frmdt.salesvolume); htmlBody = htmlBody.Replace("{averageticket}", frmdt.averageticket); htmlBody = htmlBody.Replace("{terminals}", frmdt.terminals); htmlBody = htmlBody.Replace("{chargemethod}", frmdt.chargemethod); // If we have agent details.. // USE HIDDENFIELDS FOR THIS SO YOU CAN DO THIS EARLY ON if (Request["eid"] != null) { // We have an EID - so we need to fetch the Referr By var sp_emailid = 0; var sp_emailid_string = Custom.GetNumbers(Server.HtmlEncode(Request["eid"].ToString())); // We are only interested in the numbers part of this variable Int32.TryParse(sp_emailid_string, out sp_emailid); if (sp_emailid > 0) { htmlBody = Get_EmailData(sp_emailid, htmlBody); } } else { var sp_callcenter = "None/NA"; var sp_agentfirst = ""; var sp_agentlast = ""; var sp_agentid = ""; var sp_calltime = ""; var sp_ani = ""; var sp_dnis = ""; htmlBody = htmlBody.Replace("{callcenter}", sp_callcenter); htmlBody = htmlBody.Replace("{agentfirstname}", sp_agentfirst); htmlBody = htmlBody.Replace("{agentlastname}", sp_agentlast); htmlBody = htmlBody.Replace("{agentid}", sp_agentid); htmlBody = htmlBody.Replace("{calltime}", sp_calltime); htmlBody = htmlBody.Replace("{ani}", sp_ani); htmlBody = htmlBody.Replace("{dnis}", sp_dnis); } #endregion htmlBody = htmlBody.Replace("{timestamp}", DateTime.UtcNow.ToString("MM/dd/yyyy HH:mm:ss")); htmlBody = htmlBody.Replace("{year}", DateTime.UtcNow.Year.ToString()); var smtp = new SmtpClient { Host = "smtp.gmail.com", Port = 587, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(senderEmail.Address, senderPassword) }; var message = new MailMessage(senderEmail, emailAddress); message.Subject = emailSubject; message.IsBodyHtml = true; #region Do the Attachments var attCount = Get_Attachments(message); htmlBody = htmlBody.Replace("{statements}", attCount.ToString()); #endregion message.Body = htmlBody; if (Request.Url.Host == "devapp.cardgroupintl.com") { // DeBug Client var to2Name = System.Configuration.ConfigurationManager.AppSettings["to2Name"]; var to2Email = System.Configuration.ConfigurationManager.AppSettings["to2Email"]; var emailAddress2 = new MailAddress(to2Email, to2Name); // DeBug Admin var to3Name = System.Configuration.ConfigurationManager.AppSettings["to3Name"]; var to3Email = System.Configuration.ConfigurationManager.AppSettings["to3Email"]; var emailAddress3 = new MailAddress(to3Email, to3Name); message.To.Add(emailAddress2); message.To.Add(emailAddress3); } try { smtp.Send(message); emailSent = true; } catch (Exception ex) { emailSent = false; lblProcessMessage.Text = "Error sending email"; lblProcessMessage.Text += String.Format("<table class='table_error'>" + "<tr><td>Error<td/><td>{0}</td></tr>" + "<tr><td>Message<td/><td>{1}</td></tr>" + "<tr><td>StackTrace<td/><td>{2}</td></tr>" + "<tr><td>Source<td/><td>{3}</td></tr>" + "<tr><td>InnerException<td/><td>{4}</td></tr>" + "<tr><td>Data<td/><td>{5}</td></tr>" + "</table>" , "Email Sender" //0 , ex.Message //1 , ex.StackTrace //2 , ex.Source //3 , ex.InnerException //4 , ex.Data //5 , ex.HelpLink , ex.TargetSite ); } return(emailSent); }
protected Boolean Send_Email_Client() { var emailSent = false; From_Data frmdt = getFormData(); var emailAddress = new MailAddress(frmdt.emailaddress, frmdt.contactname); var emailUser = System.Configuration.ConfigurationManager.AppSettings["mail1User"]; var emailName = System.Configuration.ConfigurationManager.AppSettings["mail1Name"]; var emailPass = System.Configuration.ConfigurationManager.AppSettings["mail1Pass"]; var senderEmail = new MailAddress(emailUser, emailName); string senderPassword = emailPass; const string emailSubject = "Credit Card Processing - Quote Request"; var emailFile = "Application_Quote.html"; var emailPath = "Emails/"; System.IO.StreamReader rdr = new System.IO.StreamReader(Server.MapPath(emailPath + emailFile)); var htmlBody = rdr.ReadToEnd(); rdr.Close(); rdr.Dispose(); // Update html variables htmlBody = htmlBody.Replace("{agentname}", "Noel Ciambotti"); // Defaulted htmlBody = htmlBody.Replace("{merchantname}", frmdt.contactname); htmlBody = htmlBody.Replace("{unsubscribe_host}", Request.Url.Host); htmlBody = htmlBody.Replace("{unsubscribe_email}", frmdt.emailaddress); var smtp = new SmtpClient { Host = "smtp.gmail.com", Port = 587, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(senderEmail.Address, senderPassword) }; var message = new MailMessage(senderEmail, emailAddress); message.Subject = emailSubject; message.IsBodyHtml = true; message.Body = htmlBody; if (Request.Url.Host == "devapp.cardgroupintl.com") { // DeBug Client var to2Name = System.Configuration.ConfigurationManager.AppSettings["to2Name"]; var to2Email = System.Configuration.ConfigurationManager.AppSettings["to2Email"]; var emailAddress2 = new MailAddress(to2Email, to2Name); // DeBug Admin var to3Name = System.Configuration.ConfigurationManager.AppSettings["to3Name"]; var to3Email = System.Configuration.ConfigurationManager.AppSettings["to3Email"]; var emailAddress3 = new MailAddress(to3Email, to3Name); message.To.Add(emailAddress2); message.To.Add(emailAddress3); } try { smtp.Send(message); emailSent = true; } catch (Exception ex) { emailSent = false; lblProcessMessage.Text = "Error sending email"; lblProcessMessage.Text += String.Format("<table class='table_error'>" + "<tr><td>Error<td/><td>{0}</td></tr>" + "<tr><td>Message<td/><td>{1}</td></tr>" + "<tr><td>StackTrace<td/><td>{2}</td></tr>" + "<tr><td>Source<td/><td>{3}</td></tr>" + "<tr><td>InnerException<td/><td>{4}</td></tr>" + "<tr><td>Data<td/><td>{5}</td></tr>" + "</table>" , "Email Sender" //0 , ex.Message //1 , ex.StackTrace //2 , ex.Source //3 , ex.InnerException //4 , ex.Data //5 , ex.HelpLink , ex.TargetSite ); } return(emailSent); }