private void SendMessage() { var objSendEmail = new SendMail(); objSendEmail.IsHTML = true; objSendEmail.Subject = "Quick Question from pinnacle3learning.com"; string body = "<b>Name</b><br>" + txtName.Text.Trim() + "<br>"; body += "<b>Email</b><br>" + txtEmail.Text.Trim() +"<br>"; body += "<b>Question/Message</b><br>" + txtQuestions.Text + "<br>"; objSendEmail.Body = body; SendMail.Send(objSendEmail, false); }
public static void Send(SendMail sendMail, bool isError) { if (ConfigurationManager.AppSettings["SendEmails"].ToLower() != "true") return; MailMessage message = new MailMessage(); message.From = new MailAddress(sendMail.From, "Pinnacle 3 Learning"); if (!string.IsNullOrEmpty(sendMail.toEmail)) message.To.Add(new MailAddress(sendMail.toEmail)); message.Subject = sendMail.subject; message.IsBodyHtml = sendMail.isHTML; if (!isError && ConfigurationManager.AppSettings["BccRegularEmailsToAddresses"] == "true") { if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["email1"])) { var address = new MailAddress(ConfigurationManager.AppSettings["email1"]); message.Bcc.Add(address); } if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["email2"])) { var address = new MailAddress(ConfigurationManager.AppSettings["email2"]); message.Bcc.Add(address); } if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["email3"])) { var address = new MailAddress(ConfigurationManager.AppSettings["email3"]); message.Bcc.Add(address); } } if (isError && ConfigurationManager.AppSettings["BccErrorEmailsToAddresses"] == "true") { if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["errorEmail1"])) { var address = new MailAddress(ConfigurationManager.AppSettings["errorEmail1"]); message.Bcc.Add(address); } if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["errorEmail2"])) { var address = new MailAddress(ConfigurationManager.AppSettings["errorEmail2"]); message.Bcc.Add(address); } if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["errorEmail3"])) { var address = new MailAddress(ConfigurationManager.AppSettings["errorEmail3"]); message.Bcc.Add(address); } } if (sendMail.Attachments!= null) foreach (Attachment a in sendMail.Attachments) { message.Attachments.Add(a); } SmtpClient Client = new SmtpClient(); message.Body = sendMail.body; try { // if there are attachments, clone the email without them so we don't clog the admin's inbox if (message.Attachments.Count > 0 && ConfigurationManager.AppSettings["IncludeAttachmentsInEmailsToAdmin"] == "false") { MailMessage copy = new MailMessage(); copy.From = message.From; copy.Subject = message.Subject; copy.IsBodyHtml = message.IsBodyHtml; copy.Body = message.Body; foreach (MailAddress b in message.Bcc) { // add the admin email addresses to the To line of the copy copy.To.Add(b); // remove the admin email addresses from the Bcc line of the message message.Bcc.Remove(b); } Client.Send(copy); } Client.Send(message); } catch (FormatException formatException) { throw new Exception("You must provide valid e-mail address." + formatException.Message); } catch (InvalidOperationException invalidException) { throw new Exception("Please Provide a Server Name. Error: " + invalidException.Message); } catch (SmtpFailedRecipientException failedrecipientException) { try { Client.Send(message); } catch { throw new Exception("Error: " + failedrecipientException.Message); } } catch (Exception ex) { throw new Exception("Error: " + ex.Message); } }
protected void nextStep_Click(object sender, EventArgs e) { if (!validateForm()) return; int amountToCharge = Convert.ToInt32(ViewState["originalamount"]); string firstName = billTo_firstName.Text; string lastName = billTo_lastName.Text; string city = billTo_city.Text; string country = billTo_country.Text; string address = billTo_street1.Text; string state = billTo_state.Text; string zip = billTo_postalCode.Text; string phone = billTo_phoneNumber.Text; string email = billTo_email.Text; string numstudents = "1"; // numberOfStudents.SelectedValue.ToString(); string comments = billto_comments.Text; string couponcode = ""; // couponCode.Text; string registrationId = "0"; string company = txtcompany.Text; string leadsource = (findUs.SelectedItem.Text + " " + sourceOther.Text); var conn = new OleDbConnection(ConfigurationManager.ConnectionStrings["classDBF"].ConnectionString); conn.Open(); try { string insertSql = string.Format( "Insert Into registration ( classId, amounttocharge, firstname, lastname, address, city , state, zipcode, country, phone, email, numstudents, couponcode, comments, DateCreated, company, leadsource ) " + " values ({0},{1},'{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}',{11},'{12}', '{13}', '" + DateTime.Now + "','{14}', '{15}')", classID.Text, amountToCharge, firstName, lastName, address, city, state, zip, country, phone, email, numstudents, couponcode, comments, company, leadsource); var cmd = new OleDbCommand(insertSql, conn); cmd.ExecuteNonQuery(); cmd = new OleDbCommand("select max(registrationid) from registration", conn); registrationId = cmd.ExecuteScalar().ToString(); } catch (Exception ex) { Response.Write(ex.Message); return; } finally { conn.Close(); } if (ConfigurationManager.AppSettings["SendLeadsToSalesForce"] == "true") { try { var sf = new SalesForceHelper(); var lead = new Lead(); lead.FirstName = firstName; lead.LastName = lastName; lead.Company = company; lead.Email = email; lead.Phone = phone; if (leadsource.Length > 40) leadsource = leadsource.Substring(0, 40); lead.LeadSource = leadsource; lead.Street = address; lead.City = city; lead.State = state; lead.PostalCode = zip; lead.Description = "Web Site Registration Initiated - " + locationLabel.Text + " " + ClassHeader1.ClassType + " " + classDate.Text + " Comments: " + billto_comments.Text; var sr = sf.Binding.create(new sObject[] {lead}); foreach (var s in sr) { if (s.success) { Session["LeadId"] = s.id; break; } throw new Exception(string.Format("Error creating Lead: {0}", s.errors[0].message)); } } catch (Exception ex) { var objSendEmail = new SendMail(); objSendEmail.IsHTML = true; objSendEmail.Subject = "Error on pinnacle3learning.com - SalesForce Integration"; string body = "<b>Message</b><br>" + ex.Message + "<br><br>"; body += "<b>Attempting to Create Lead</b><br>" + firstName + " " + lastName + "<br><br>"; body += "<b>Page</b><br>register.aspx<br><br>"; body += "<b>Inner Exception</b><br>" + ex.InnerException + "<br><br>"; body += "<b>Stack Trace</b><br>" + ex.StackTrace + "<br><br>"; body += "<b>TimeStamp</b><br>" + DateTime.Now.ToString() + "<br><br>"; objSendEmail.Body = body; SendMail.Send(objSendEmail, true); } } nextStep.Visible = false; string url; // if the config setting allows it, go secure for the rest of the user's visit. if (ConfigurationManager.AppSettings["GoSecure"] == "true") { url = String.Format("https://{0}{1}", Request.ServerVariables["HTTP_HOST"], ResolveUrl("~/confirm.aspx?registrationid=" + registrationId)); } else { url = "confirm.aspx?registrationid=" + registrationId; } var redirect = "window.location.href='" + url + "'"; ScriptManager.RegisterStartupScript(Page, Page.GetType(), Guid.NewGuid().ToString(), redirect, true); }
public static void Send(SendMail sendMail) { Send(sendMail, false); }
protected void Page_Load(object sender, EventArgs e) { pnlSiteSeal.Visible = Request.Url.Scheme == "https" || !bool.Parse(ConfigurationManager.AppSettings["GoSecure"]); if (!IsPostBack) { if (Request.QueryString["registrationid"] == null) throw new Exception("Registration ID was discovered to be null when initiating the confiremd page."); string registrationid = Request.QueryString["registrationid"]; string classId = string.Empty; string locationDesc = string.Empty; string locationSeo = string.Empty; string hotel = string.Empty; string hotelWebsite = string.Empty; string description = string.Empty; string classTypeDesc = string.Empty; string classDays = string.Empty; bool hot = false; DateTime classDateTime = DateTime.MaxValue; AmountToCharge = 0; string firstName = string.Empty; string lastName = string.Empty; string city = string.Empty; string country = string.Empty; string address = string.Empty; string state = string.Empty; string zip = string.Empty; string phone = string.Empty; string email = string.Empty; string numstudents = string.Empty; string comments = string.Empty; string couponcode = string.Empty; string paymenttype = string.Empty; string company = string.Empty; OleDbConnection conn = new OleDbConnection(ConfigurationManager.ConnectionStrings["classDBF"].ConnectionString); OleDbCommand cmd = new OleDbCommand("SELECT classes.ClassID, classes.HOT, (Format(classes.ClassDate,'mm/dd/yyyy')) AS ClassDate, classes.numdays, ClassType.classTypeDesc, DaysOfWeek.Description, Hotels.Hotel, Hotels.HotelWebsite, Locations.LocationSeo, Locations.LocationDesc, registration.RegistrationId, registration.amounttocharge, registration.firstname, registration.lastname, registration.company, registration.address, registration.city, registration.state, registration.zipcode, registration.country, registration.phone, registration.email, registration.numstudents, registration.couponcode, registration.comments, registration.paymenttype FROM (Locations INNER JOIN (ClassType INNER JOIN (Hotels INNER JOIN (DaysOfWeek INNER JOIN classes ON DaysOfWeek.DaysOfWeekID = classes.ClassDaysID) ON Hotels.HotelID = classes.HotelID) ON ClassType.classTypeID = classes.ClassTypeID) ON Locations.LocationID = classes.LocationID) INNER JOIN registration ON classes.ClassID = registration.classId WHERE registration.RegistrationId=" + registrationid, conn); conn.Open(); OleDbDataReader myReader = cmd.ExecuteReader(); while (myReader.Read()) { classId = myReader["ClassID"].ToString(); locationDesc = myReader["LocationDesc"].ToString(); locationSeo = myReader["LocationSeo"].ToString(); hotel = myReader["Hotel"].ToString(); hotelWebsite = myReader["HotelWebsite"].ToString(); description = myReader["Description"].ToString(); hot = myReader["HOT"].ToString() == "images/discount_img.jpg"; classDateTime = DateTime.Parse(myReader["ClassDate"].ToString()); classTypeDesc = myReader["classTypeDesc"].ToString(); AmountToCharge = int.Parse(myReader["amounttocharge"].ToString()); firstName = myReader["firstName"].ToString(); lastName = myReader["lastName"].ToString(); city = myReader["city"].ToString(); country = myReader["country"].ToString(); address = myReader["address"].ToString(); state = myReader["state"].ToString(); zip = myReader["zipcode"].ToString(); phone = myReader["phone"].ToString(); email = myReader["email"].ToString(); numstudents = myReader["numstudents"].ToString(); comments = myReader["comments"].ToString(); couponcode = myReader["couponcode"].ToString(); paymenttype = myReader["paymenttype"].ToString(); company = myReader["company"].ToString(); break; } myReader.Close(); conn.Close(); lblRegistration.Text = registrationid.ToString(); lblClassDate.Text = classDateTime.ToShortDateString(); lblClassLocation.Text = locationDesc; lblPrice.Text = string.Format("{0:C}", AmountToCharge); lblClassDays.Text = description; lblHotel.Text = hotel; billTo_city.Text = city; billto_comments.Text = comments; billTo_country.Text = country; billTo_email.Text = email; billTo_firstName.Text = firstName; billTo_lastName.Text = lastName; billTo_phoneNumber.Text = phone; billTo_postalCode.Text = zip; billTo_state.Text = state; billTo_street1.Text = address; lblPayment.Text = paymenttype; lblCompany.Text = company; var locationLink = string.Empty; switch (classTypeDesc) { case "PMP": lblClass.Text = "Project Management Professional (PMP®) Prep"; locationLink = "pmp-certification-" + locationSeo; break; case "Essentials": lblClass.Text = "PM Essentials"; break; case "Risk": lblClass.Text = "Managing Project Risk"; break; case "MS Project": lblClass.Text = "Microsoft Project 2007 Training"; break; case "CAPM": lblClass.Text = "Certified Associate in Project Management"; locationLink = locationSeo + "-capm-training-class"; break; case "L6BI": lblClass.Text = "Lean Six Sigma Black Belt Program"; locationLink = locationSeo + "-lean-six-sigma-green-belt-training-class"; break; case "L6GI": lblClass.Text = "Lean Six Sigma Green Belt Program"; locationLink = locationSeo + "-lean-six-sigma-green-belt-training-class"; break; } hotelInfoLink.NavigateUrl = locationLink; if (ConfigurationManager.AppSettings["SendLeadsToSalesForce"] == "true") { string days; if (classDays.Contains("Sat")) { days = "WKND"; } else { days = "WKDY"; } string optyname = locationDesc.ToUpper().Replace(".", "").Replace(" ", "").Substring(0, 3) + " " + classTypeDesc.ToUpper().Replace(" ", "").Substring(0, 3) + " " + days + " - " + lastName + "." + firstName.Substring(0, 1); _doSalesForceWork(optyname, company, AmountToCharge, locationDesc, classDateTime); } SendMail objSendEmail = new SendMail(); ///send notification in email objSendEmail.IsHTML = true; objSendEmail.ToEmail = email; objSendEmail.Subject = "Pinnacle 3 Learning Registration Confirmation"; objSendEmail.Body = string.Format(P3Strings.EmailNotificationOfRegistrationConfirmationBody, registrationid, lblClass.Text, locationDesc, classDateTime.ToShortDateString(), description, "8:30am - 6:00pm", "http://" + Request.ServerVariables["HTTP_HOST"] + "/" + locationLink, hotel, firstName, lastName, address, city, state, zip, country, phone, email, lblPrice.Text, paymenttype, numstudents, company, comments); try { SendMail.Send(objSendEmail); } catch { lblEmail.Text = "We were unable to send the automatic confirmation email. We'll send it to you manually as soon as possible."; } } }
private void _doSalesForceWork(string opportunityName, string companyName, int amountToCharge, string targetLocation, DateTime targetDate) { try { if (Session["LeadId"] == null || string.IsNullOrEmpty(Session["LeadId"].ToString())) return; // Retrieve the Lead record; string leadId = Session["LeadId"].ToString(); string accountId = ""; SalesForceHelper sf = new SalesForceHelper(); QueryResult qr = null; sf.Binding.QueryOptionsValue = new QueryOptions(); sf.Binding.QueryOptionsValue.batchSize = 250; sf.Binding.QueryOptionsValue.batchSizeSpecified = true; qr = sf.Binding.query("select Id, Name from Account where name = '" + companyName + "'"); if (qr != null && qr.records != null) foreach (sObject t in qr.records) { Account a = (Account) t; accountId = a.Id; break; } string optyId = sf.ConvertLeadToOpportunity(leadId, accountId, opportunityName); sObject[] records = sf.Binding.retrieve("Id, Name, StageName", "Opportunity", new[] {optyId}); if (records.Length == 1) { Opportunity opty = (Opportunity) records[0]; opty.StageName = "Proposal/Price Quote"; opty.Description = "Web Site Registration Confirmed & Unpaid - " + lblClassLocation.Text + " " + lblClass.Text + " " + lblClassDate.Text + " " + lblClassDays.Text + " Comments: " + billto_comments.Text; opty.Amount = amountToCharge; opty.AmountSpecified = true; opty.Target_Date__c = targetDate; opty.Target_Date__cSpecified = true; opty.Target_Location__c = targetLocation; sf.Binding.update(new[] {opty}); } sf.Binding.logout(); } catch (Exception ex) { SendMail objSendEmail = new SendMail(); objSendEmail.IsHTML = true; objSendEmail.Subject = "Error on pinnacle3learning.com - SalesForce Integration "; string body = "<b>Message</b><br>" + ex.Message + "<br><br>"; body += "<b>Attempting to Convert Lead</b><br>" + opportunityName + "<br><br>"; body += "<b>Page</b><br>confirmed-paid.aspx<br><br>"; body += "<b>Inner Exception</b><br>" + ex.InnerException + "<br><br>"; body += "<b>Stack Trace</b><br>" + ex.StackTrace + "<br><br>"; body += "<b>TimeStamp</b><br>" + DateTime.Now.ToString() + "<br><br>"; objSendEmail.Body = body; SendMail.Send(objSendEmail, true); } }
private void sendCCEmail(decimal chargeAmount) { SendMail objSendEmail = new SendMail(); objSendEmail.IsHTML = true; objSendEmail.Subject = "Credit Card Info for Registration " + Request.QueryString["registrationid"] + " Initiated By " + billTo_firstName.Text.Trim() + " " + billTo_lastName.Text.Trim(); objSendEmail.Body = string.Format(P3Strings.EmailNotificationOfCreditCardInfo, lblClass.Text, lblClassLocation.Text, lblClassDate.Text, chargeAmount, txtBillName.Text, txtBillCompany.Text, txtBillAddress.Text, txtBillCity.Text, txtBillState.Text, txtBillZip.Text, txtBillPhone.Text, txtBillEmail.Text, txtCardnumber.Text.Trim(), ddlExpyMonth.SelectedValue, ddlExpyYear.SelectedValue, txtCcv.Text.Trim(), billTo_firstName.Text + " " + billTo_lastName.Text, Request.QueryString["registrationid"], ddlPaymentType.SelectedValue ); try { SendMail.Send(objSendEmail); } catch { Response.Write("Error sending registration email"); } }
protected void Page_Load(object sender, EventArgs e) { _acceptCreditCards = bool.Parse(ConfigurationManager.AppSettings["AcceptCreditCards"]); _creditCard_Test50Cents = bool.Parse(ConfigurationManager.AppSettings["CreditCard_Test50Cents"]); _creditCard_AuthorizationActive = bool.Parse(ConfigurationManager.AppSettings["CreditCard_AuthorizationActive"]); pnlSiteSeal.Visible = Request.Url.Scheme == "https" || !bool.Parse(ConfigurationManager.AppSettings["GoSecure"]); if (!IsPostBack) { _initPage(); if (Request.QueryString["registrationid"] == null) { Response.Redirect("classschedule.aspx"); } else { string registrationid = Request.QueryString["registrationid"]; string classId = string.Empty; string locationDesc = string.Empty; string hotel = string.Empty; string hotelWebsite = string.Empty; string description = string.Empty; classTypeDesc = string.Empty; string classDays = string.Empty; bool hot = false; DateTime classDateTime = DateTime.MaxValue; AmountToCharge = 0; string firstName = string.Empty; string lastName = string.Empty; string city = string.Empty; string country = string.Empty; string address = string.Empty; string state = string.Empty; string zip = string.Empty; string phone = string.Empty; string email = string.Empty; string numstudents = string.Empty; string comments = string.Empty; string couponcode = string.Empty; string company = string.Empty; string leadsource = string.Empty; OleDbConnection conn = new OleDbConnection(ConfigurationManager.ConnectionStrings["classDBF"].ConnectionString); OleDbCommand cmd = new OleDbCommand("SELECT classes.ClassID, classes.HOT, (Format(classes.ClassDate,'mm/dd/yyyy')) AS ClassDate, classes.numdays, ClassType.classTypeDesc, DaysOfWeek.Description, Hotels.Hotel, Hotels.HotelWebsite, Locations.LocationDesc, registration.RegistrationId, registration.amounttocharge, registration.firstname, registration.lastname, registration.company, registration.leadsource, registration.address, registration.city, registration.state, registration.zipcode, registration.country, registration.phone, registration.email, registration.numstudents, registration.couponcode, registration.comments FROM (Locations INNER JOIN (ClassType INNER JOIN (Hotels INNER JOIN (DaysOfWeek INNER JOIN classes ON DaysOfWeek.DaysOfWeekID = classes.ClassDaysID) ON Hotels.HotelID = classes.HotelID) ON ClassType.classTypeID = classes.ClassTypeID) ON Locations.LocationID = classes.LocationID) INNER JOIN registration ON classes.ClassID = registration.classId WHERE registration.RegistrationId=" + registrationid, conn); conn.Open(); OleDbDataReader myReader = cmd.ExecuteReader(); while (myReader.Read()) { classId = myReader["ClassID"].ToString(); hypBack.NavigateUrl = "javascript: window.history.back()"; locationDesc = myReader["LocationDesc"].ToString(); hotel = myReader["Hotel"].ToString(); hotelWebsite = myReader["HotelWebsite"].ToString(); description = myReader["Description"].ToString(); hot = myReader["HOT"].ToString() == "images/discount_img.jpg"; classDateTime = DateTime.Parse(myReader["ClassDate"].ToString()); classTypeDesc = myReader["classTypeDesc"].ToString(); AmountToCharge = int.Parse(myReader["amounttocharge"].ToString()); ViewState["AmountToCharge"] = AmountToCharge; firstName = myReader["firstName"].ToString(); lastName = myReader["lastName"].ToString(); city = myReader["city"].ToString(); country = myReader["country"].ToString(); address = myReader["address"].ToString(); state = myReader["state"].ToString(); zip = myReader["zipcode"].ToString(); phone = myReader["phone"].ToString(); email = myReader["email"].ToString(); numstudents = myReader["numstudents"].ToString(); comments = myReader["comments"].ToString(); couponcode = myReader["couponcode"].ToString(); company = myReader["company"].ToString(); leadsource = myReader["leadsource"].ToString(); break; } myReader.Close(); conn.Close(); lblClassDate.Text = classDateTime.ToShortDateString(); lblClassLocation.Text = locationDesc; lblPrice.Text = string.Format("{0:C}", AmountToCharge); lblClassDays.Text = description; lblHotel.Text = hotel; hotelInfoLink.NavigateUrl = hotelWebsite; billTo_city.Text = city; billto_comments.Text = comments; billTo_country.Text = country; billTo_email.Text = email; billTo_firstName.Text = firstName; billTo_lastName.Text = lastName; billTo_phoneNumber.Text = phone; billTo_postalCode.Text = zip; billTo_state.Text = state; billTo_street1.Text = address; //lblNumStudents.Text = numstudents; txtBillName.Text = firstName + " " + lastName; lblCompany.Text = company; txtBillAddress.Text = address; txtBillCity.Text = city; txtBillState.Text = state; txtBillZip.Text = zip; txtBillPhone.Text = phone; txtBillEmail.Text = email; txtBillCompany.Text = company; switch (classTypeDesc) { case "PMP": lblClass.Text = "Project Management Professional (PMP®) Prep"; break; case "Essentials": lblClass.Text = "PM Essentials"; break; case "Risk": lblClass.Text = "Managing Project Risk"; break; case "MS Project": lblClass.Text = "Microsoft Project 2007 Training"; break; case "CAPM": lblClass.Text = "Certified Associate in Project Management"; break; case "L6BI": lblClass.Text = "Lean Six Sigma Black Belt Program"; break; case "L6GI": lblClass.Text = "Lean Six Sigma Green Belt Program"; break; } SendMail objSendEmail = new SendMail(); objSendEmail.IsHTML = true; objSendEmail.Subject = "Registration " + Request.QueryString["registrationid"] + " Initiated By " + billTo_firstName.Text.Trim() + " " + billTo_lastName.Text.Trim(); objSendEmail.Body = string.Format(P3Strings.EmailNotificationOfRegistrationInitiatedBody, DateTime.Now.ToString(), lblClass.Text, lblClassLocation.Text, lblClassDate.Text, lblPrice.Text, billTo_firstName.Text.Trim(), billTo_lastName.Text.Trim(), billTo_street1.Text.Trim(), billTo_city.Text.Trim(), billTo_state.Text.Trim(), billTo_postalCode.Text.Trim(), billTo_country.Text.Trim(), billTo_phoneNumber.Text.Trim(), billTo_email.Text.Trim(), string.Empty, company, leadsource); try { SendMail.Send(objSendEmail); } catch(Exception ex) { Response.Write("Error sending registration email: " + ex.Message); } } } }