private static string HTML_Send_Email(string Recepient_List, string CcList, string Comments, string User_Name, string SobekCM_Instance_Name, string URL, string URL_Title, string URL_Short_Type, int UserID ) { try { StringBuilder messageBuilder = new StringBuilder(); messageBuilder.Append("<span style=\"font-family:Arial, Helvetica, sans-serif;\">"); if ((Comments.Length > 0) && ( Comments != URL_Title )) { messageBuilder.AppendLine(User_Name + " wanted you to see this " + URL_Short_Type + " on " + SobekCM_Instance_Name + " and included the following comments.<br /><br />\n"); messageBuilder.AppendLine(Comments.Replace("<", "(").Replace(">", ")").Replace("\"", """) + ".<br /><br />\n"); } else { messageBuilder.AppendLine(User_Name + " wanted you to see this " + URL_Short_Type + " on " + SobekCM_Instance_Name + ".<br /><br />\n"); } messageBuilder.AppendLine("<a href=\"" + URL + "\">" + URL_Title + "</a>"); messageBuilder.AppendLine("</span>"); string[] email_recepients = Recepient_List.Split(";,".ToCharArray()); foreach (string thisEmailRecepient in email_recepients) { EmailInfo newEmail = new EmailInfo { Body = messageBuilder.ToString(), isContactUs = false, isHTML = true, Subject = URL_Short_Type + " from " + SobekCM_Instance_Name, RecipientsList = thisEmailRecepient, FromAddress = SobekCM_Instance_Name + " <" + UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromAddress + ">", UserID = UserID }; if (!String.IsNullOrEmpty(UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromDisplay)) newEmail.FromAddress = UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromDisplay + " <" + UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromAddress + ">"; if (CcList.Length > 0) newEmail.RecipientsList = thisEmailRecepient.Trim() + "," + CcList; string error; if (!Email_Helper.SendEmail(newEmail, out error)) return error; } return String.Empty; } catch (Exception ee) { return ee.Message; } }
/// <summary> Sends an email using the currently selected email method ( i.e., direct SMTP or database mail ) </summary> /// <param name="ToAddress"> To address for the email to send </param> /// <param name="Subject"> Subject line for the email to send </param> /// <param name="Body"> Body of the email to send </param> /// <param name="isHtml"> If set to <c>true</c>, send the email as HTML format (vs. text format) </param> /// <param name="InstanceName"> Name of the current SobekCM instance </param> /// <returns> TRUE if successful, otherwise FALSE </returns> public static bool SendEmail(string ToAddress, string Subject, string Body, bool isHtml, string InstanceName) { EmailInfo newEmail = new EmailInfo {RecipientsList = ToAddress, Subject = Subject, Body = Body, isHTML = isHtml}; if (String.IsNullOrEmpty(Engine_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromDisplay)) { newEmail.FromAddress = InstanceName + " <" + Engine_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromAddress + ">"; } else { newEmail.FromAddress = Engine_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromDisplay + " <" + Engine_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromAddress + ">"; } string ignore_error_msg; return SendEmail(newEmail, out ignore_error_msg); }
private static bool HTML_Send_Email(string Recepient_List, string CcList, string Comments, string User_Name, string SobekCM_Instance_Name, BriefItemInfo Item, string URL, int UserID) { try { StringBuilder messageBuilder = new StringBuilder(); messageBuilder.AppendLine("<span style=\"font-family:Arial, Helvetica, sans-serif;\">"); if (Comments.Length > 0) { messageBuilder.AppendLine(User_Name + " wanted you to see this item on " + SobekCM_Instance_Name + " and included the following comments.<br /><br />\n"); messageBuilder.AppendLine(Comments.Replace("<", "(").Replace(">", ")").Replace("\"", """) + ".<br /><br />\n"); } else { messageBuilder.AppendLine(User_Name + " wanted you to see this item on " + SobekCM_Instance_Name + ".<br /><br />\n"); } messageBuilder.AppendLine("<table cellspacing=\"0px\" cellpadding=\"0px\">\n"); messageBuilder.AppendLine("<tr><td colspan=\"2\" style=\"background: black; color: white; font-family:Arial, Helvetica, sans-serif;\"><b>ITEM INFORMATION</b></td></tr>\n"); // Include the thumbnail, if one exists if (String.IsNullOrEmpty(Item.Behaviors.Main_Thumbnail)) messageBuilder.AppendLine("<tr>"); else messageBuilder.AppendLine("<tr valign=\"top\"><td><a href=\"" + URL + "\"><img src=\"" + Item.Web.Source_URL.Replace("\\", "/") + "/" + Item.Behaviors.Main_Thumbnail + "\" alt=\"BLOCKED THUMBNAIL IMAGE\" border=\"1px\" /></a></td>\n"); messageBuilder.AppendLine("<td>"); messageBuilder.AppendLine("<table style=\"font-family:Arial, Helvetica, sans-serif; font-size:smaller;\">"); // Step through the citation configuration here CitationSet citationSet = UI_ApplicationCache_Gateway.Configuration.UI.CitationViewer.Get_CitationSet("EMAIL"); foreach (CitationFieldSet fieldsSet in citationSet.FieldSets) { // Check to see if any of the values indicated in this field set exist bool foundExistingData = false; foreach (CitationElement thisField in fieldsSet.Elements) { // Look for a match in the item description BriefItem_DescriptiveTerm briefTerm = Item.Get_Description(thisField.MetadataTerm); // If no match, just continue if ((briefTerm != null) && (briefTerm.Values.Count > 0)) { foundExistingData = true; break; } } // If no data was found to put in this field set, skip it if (!foundExistingData) continue; // Step through all the fields in this field set and write them foreach (CitationElement thisField in fieldsSet.Elements) { // Look for a match in the item description BriefItem_DescriptiveTerm briefTerm = Item.Get_Description(thisField.MetadataTerm); // If no match, just continue if ((briefTerm == null) || (briefTerm.Values.Count == 0)) continue; // If they can all be listed one after the other do so now if (!thisField.IndividualFields) { List<string> valueArray = new List<string>(); foreach (BriefItem_DescTermValue thisValue in briefTerm.Values) { if (String.IsNullOrEmpty(thisValue.Authority)) { if (String.IsNullOrEmpty(thisValue.Language)) { valueArray.Add(HttpUtility.HtmlEncode(thisValue.Value)); } else { valueArray.Add(HttpUtility.HtmlEncode(thisValue.Value) + " ( " + thisValue.Language + " )"); } } else { if (String.IsNullOrEmpty(thisValue.Language)) { valueArray.Add(HttpUtility.HtmlEncode(thisValue.Value) + " ( " + thisValue.Authority + " )"); } else { valueArray.Add(HttpUtility.HtmlEncode(thisValue.Value) + " ( " + thisValue.Authority + ", " + thisValue.Language + " )"); } } } // Now, add this to the citation HTML Add_Citation_HTML_Rows(thisField.DisplayTerm, valueArray, messageBuilder); } else { // In this case, each individual value gets its own citation html row foreach (BriefItem_DescTermValue thisValue in briefTerm.Values) { // Determine the label string label = thisField.DisplayTerm; if (thisField.OverrideDisplayTerm == CitationElement_OverrideDispayTerm_Enum.subterm) { if (!String.IsNullOrEmpty(thisValue.SubTerm)) label = thisValue.SubTerm; } if (String.IsNullOrEmpty(thisValue.Authority)) { if (String.IsNullOrEmpty(thisValue.Language)) { messageBuilder.Append(Single_Citation_HTML_Row(label, HttpUtility.HtmlEncode(thisValue.Value))); } else { messageBuilder.Append(Single_Citation_HTML_Row(label, HttpUtility.HtmlEncode(thisValue.Value) + " ( " + thisValue.Language + " )")); } } else { if (String.IsNullOrEmpty(thisValue.Language)) { messageBuilder.Append(Single_Citation_HTML_Row(label, HttpUtility.HtmlEncode(thisValue.Value) + " ( " + thisValue.Authority + " )")); } else { messageBuilder.Append(Single_Citation_HTML_Row(label, HttpUtility.HtmlEncode(thisValue.Value) + " ( " + thisValue.Authority + ", " + thisValue.Language + " )")); } } } } } } messageBuilder.AppendLine("</table>"); messageBuilder.AppendLine("</td></tr></table>"); messageBuilder.AppendLine("</span>\n"); string[] email_recepients = Recepient_List.Split(";,".ToCharArray()); string subject = Item.Title.Replace(""", "\""); if (Item.Title.Length > 40) { subject = Item.Title.Substring(0, 35).Replace(""", "\"") + "..."; } int error_count = 0; foreach (string thisReceipient in email_recepients) { EmailInfo newEmail = new EmailInfo { Body = messageBuilder.ToString(), isContactUs = false, isHTML = true, Subject = subject, RecipientsList = thisReceipient, FromAddress = SobekCM_Instance_Name + " <" + UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromAddress + ">", UserID = UserID }; if (! String.IsNullOrEmpty(UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromDisplay)) newEmail.FromAddress = UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromDisplay + " <" + UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromAddress + ">"; if (CcList.Length > 0) newEmail.RecipientsList = thisReceipient.Trim() + "," + CcList; string error; if (!Email_Helper.SendEmail(newEmail, out error)) error_count++; } return error_count <= 0; } catch { return false; } }
private static bool Text_Send_Email(string Recepient_List, string CcList, string Comments, string User_Name, string SobekCM_Instance_Name, BriefItemInfo Item, string URL, int UserID ) { try { StringBuilder messageBuilder = new StringBuilder(); if (Comments.Length > 0) { messageBuilder.Append(User_Name + " wanted you to see this item on " + SobekCM_Instance_Name + " and included the following comments:\n\n"); messageBuilder.Append("\"" + Comments + "\"\n\n"); } else { messageBuilder.Append(User_Name + " wanted you to see this item on " + SobekCM_Instance_Name + ".\n\n"); } messageBuilder.Append("ITEM INFORMATION\n"); messageBuilder.Append("------------------------------------------------------\n"); // Step through the citation configuration here CitationSet citationSet = UI_ApplicationCache_Gateway.Configuration.UI.CitationViewer.Get_CitationSet("EMAIL"); foreach (CitationFieldSet fieldsSet in citationSet.FieldSets) { // Check to see if any of the values indicated in this field set exist bool foundExistingData = false; foreach (CitationElement thisField in fieldsSet.Elements) { // Look for a match in the item description BriefItem_DescriptiveTerm briefTerm = Item.Get_Description(thisField.MetadataTerm); // If no match, just continue if ((briefTerm != null) && (briefTerm.Values.Count > 0)) { foundExistingData = true; break; } } // If no data was found to put in this field set, skip it if (!foundExistingData) continue; // Step through all the fields in this field set and write them foreach (CitationElement thisField in fieldsSet.Elements) { // Look for a match in the item description BriefItem_DescriptiveTerm briefTerm = Item.Get_Description(thisField.MetadataTerm); // If no match, just continue if ((briefTerm == null) || (briefTerm.Values.Count == 0)) continue; // If they can all be listed one after the other do so now if (!thisField.IndividualFields) { List<string> valueArray = new List<string>(); foreach (BriefItem_DescTermValue thisValue in briefTerm.Values) { if (String.IsNullOrEmpty(thisValue.Authority)) { if (String.IsNullOrEmpty(thisValue.Language)) { valueArray.Add(HttpUtility.HtmlEncode(thisValue.Value)); } else { valueArray.Add(HttpUtility.HtmlEncode(thisValue.Value) + " ( " + thisValue.Language + " )"); } } else { if (String.IsNullOrEmpty(thisValue.Language)) { valueArray.Add(HttpUtility.HtmlEncode(thisValue.Value) + " ( " + thisValue.Authority + " )"); } else { valueArray.Add(HttpUtility.HtmlEncode(thisValue.Value) + " ( " + thisValue.Authority + ", " + thisValue.Language + " )"); } } } // Now, add this to the citation HTML Add_Citation_Text_Rows(thisField.DisplayTerm, valueArray, messageBuilder); } else { // In this case, each individual value gets its own citation html row foreach (BriefItem_DescTermValue thisValue in briefTerm.Values) { // Determine the label string label = thisField.DisplayTerm; if (thisField.OverrideDisplayTerm == CitationElement_OverrideDispayTerm_Enum.subterm) { if (!String.IsNullOrEmpty(thisValue.SubTerm)) label = thisValue.SubTerm; } if (String.IsNullOrEmpty(thisValue.Authority)) { if (String.IsNullOrEmpty(thisValue.Language)) { messageBuilder.Append(Single_Citation_Text_Row(label, HttpUtility.HtmlEncode(thisValue.Value))); } else { messageBuilder.Append(Single_Citation_Text_Row(label, HttpUtility.HtmlEncode(thisValue.Value) + " ( " + thisValue.Language + " )")); } } else { if (String.IsNullOrEmpty(thisValue.Language)) { messageBuilder.Append(Single_Citation_Text_Row(label, HttpUtility.HtmlEncode(thisValue.Value) + " ( " + thisValue.Authority + " )")); } else { messageBuilder.Append(Single_Citation_Text_Row(label, HttpUtility.HtmlEncode(thisValue.Value) + " ( " + thisValue.Authority + ", " + thisValue.Language + " )")); } } } } } } string[] email_recepients = Recepient_List.Split(";,".ToCharArray()); string subject = Item.Title.Replace(""", "\""); if (Item.Title.Length > 40) { subject = Item.Title.Substring(0, 35).Replace(""", "\"") + "..."; } int error_count = 0; foreach (string thisReceipient in email_recepients) { EmailInfo newEmail = new EmailInfo { Body = messageBuilder.ToString(), isContactUs = false, isHTML = false, Subject = subject, RecipientsList = thisReceipient, FromAddress = SobekCM_Instance_Name + " <" + UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromAddress + ">", UserID = UserID }; if (!String.IsNullOrEmpty(UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromDisplay)) newEmail.FromAddress = UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromDisplay + " <" + UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromAddress + ">"; if (CcList.Length > 0) newEmail.RecipientsList = thisReceipient.Trim() + "," + CcList; string error; if (!Email_Helper.SendEmail(newEmail, out error)) error_count++; } return error_count <= 0; } catch { return false; } }
/// <summary> Constructor for a new instance of the Contact_HtmlSubwriter class </summary> /// <param name="Last_Mode"> URL for the last mode this user was in before selecting contact us</param> /// <param name="UserHistoryRequestInfo"> Some history and user information to include in the final email </param> /// <param name="RequestSpecificValues"> All the necessary, non-global data specific to the current request </param> public Contact_HtmlSubwriter(string Last_Mode, string UserHistoryRequestInfo, RequestCache RequestSpecificValues) : base(RequestSpecificValues) { // Save the parameters lastMode = Last_Mode; // Set the error message to an empty string to start with errorMsg = String.Empty; // Determine the configuration to use for this contact us form configuration = UI_ApplicationCache_Gateway.Settings.ContactForm; if ((RequestSpecificValues.Hierarchy_Object != null) && (RequestSpecificValues.Hierarchy_Object.ContactForm != null)) configuration = RequestSpecificValues.Hierarchy_Object.ContactForm; postBackValues = new Dictionary<string, string>(); foreach (string thisKey in HttpContext.Current.Request.Form.AllKeys) { if (thisKey != "item_action") { string value = HttpContext.Current.Request.Form[thisKey]; if (!String.IsNullOrEmpty(value)) { postBackValues[thisKey] = value; } } } // If this is a post back, send email if (HttpContext.Current.Request.Form["item_action"] == null) return; string action = HttpContext.Current.Request.Form["item_action"]; if (action == "email") { // Some values to collect information string subject = "Contact [" + RequestSpecificValues.Current_Mode.Instance_Abbreviation + " Submission]"; string message_from = RequestSpecificValues.Current_Mode.Instance_Abbreviation + "<" + UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromAddress + ">"; if (!String.IsNullOrEmpty(UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromDisplay)) { message_from = UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromDisplay + "<" + UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromAddress + ">"; } int text_area_count = configuration.TextAreaElementCount; StringBuilder emailBuilder = new StringBuilder(); // Make sure all the required fields are completed and build the emails StringBuilder errorBuilder = new StringBuilder(); int control_count = 1; foreach (ContactForm_Configuration_Element thisElement in configuration.FormElements) { if ((thisElement.Element_Type != ContactForm_Configuration_Element_Type_Enum.HiddenValue) && (thisElement.Element_Type != ContactForm_Configuration_Element_Type_Enum.ExplanationText)) { // Determine the name of this control string control_name = String.Empty; if (!String.IsNullOrEmpty(thisElement.Name)) control_name = thisElement.Name.Replace(" ", "_"); if (thisElement.Element_Type == ContactForm_Configuration_Element_Type_Enum.Subject) control_name = "subject"; if (thisElement.Element_Type == ContactForm_Configuration_Element_Type_Enum.Email) control_name = "email"; if (String.IsNullOrEmpty(control_name)) control_name = "Control" + control_count; if (!postBackValues.ContainsKey(control_name)) { if (thisElement.Required) errorBuilder.Append(thisElement.QueryText.Get_Value(RequestSpecificValues.Current_Mode.Language).Replace(":", "") + "<br />"); } else { if (thisElement.Element_Type == ContactForm_Configuration_Element_Type_Enum.Subject) { subject = postBackValues[control_name] + " [" + RequestSpecificValues.Current_Mode.Instance_Abbreviation + " Submission]"; } else if (thisElement.Element_Type == ContactForm_Configuration_Element_Type_Enum.Email) { string entered_message_from = postBackValues[control_name]; if (!IsValidEmail(entered_message_from)) { errorBuilder.Append(thisElement.QueryText.Get_Value(RequestSpecificValues.Current_Mode.Language).Replace(":", "") + " (INVALID) <br />"); } message_from = RequestSpecificValues.Current_Mode.Instance_Abbreviation + "<" + entered_message_from + ">"; if (!String.IsNullOrEmpty(UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromDisplay)) { message_from = UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromDisplay + "<" + entered_message_from + ">"; } emailBuilder.Append("Email:\t\t" + entered_message_from + "\n"); } else if (thisElement.Element_Type == ContactForm_Configuration_Element_Type_Enum.TextArea) { if (text_area_count == 1) { emailBuilder.Insert(0, postBackValues[control_name] + "\n\n"); } else { if (emailBuilder.Length > 0) emailBuilder.Append("\n"); emailBuilder.Append(thisElement.QueryText.Get_Value(RequestSpecificValues.Current_Mode.Language) + "\n"); emailBuilder.Append(postBackValues[control_name] + "\n\n"); } } else { emailBuilder.Append(control_name.Replace("_", " ") + ":\t\t" + postBackValues[control_name] + "\n"); } } control_count++; } } if (errorBuilder.Length > 0) { errorMsg = errorBuilder.ToString(); return; } // Create the final body string email_body = emailBuilder + "\n\n" + UserHistoryRequestInfo; // Determine the sendee string sendTo = UI_ApplicationCache_Gateway.Settings.Email.System_Email; if ((RequestSpecificValues.Hierarchy_Object != null) && (!String.IsNullOrEmpty(RequestSpecificValues.Hierarchy_Object.Contact_Email))) { sendTo = RequestSpecificValues.Hierarchy_Object.Contact_Email.Replace(";", ","); } int userid = -1; if (RequestSpecificValues.Current_User != null) userid = RequestSpecificValues.Current_User.UserID; EmailInfo newEmail = new EmailInfo { Body = email_body, isContactUs = true, isHTML = false, RecipientsList = sendTo, Subject = subject, UserID = userid, FromAddress = message_from }; string error_msg; bool email_error = !Email_Helper.SendEmail(newEmail, out error_msg); // Send back to the home for this collection, sub, or group if (email_error) { HttpContext.Current.Response.Redirect(UI_ApplicationCache_Gateway.Settings.Servers.System_Error_URL, false); HttpContext.Current.ApplicationInstance.CompleteRequest(); } else { // Send back to the home for this collection, sub, or group RequestSpecificValues.Current_Mode.Mode = Display_Mode_Enum.Contact_Sent; UrlWriterHelper.Redirect(RequestSpecificValues.Current_Mode); } } }
/// <summary> Send email according to this instance's email settings </summary> /// <param name="Email"> Complete information for this email </param> /// <param name="Error"> [OUT] Any error message encountered </param> /// <returns> TRUE if successfully queued, otherwise FALSE </returns> public static bool SendEmail(EmailInfo Email, out string Error ) { Error = String.Empty; int replyId = -1; if (Email.ReplayToEmailID.HasValue) replyId = Email.ReplayToEmailID.Value; int userId = -1; if (Email.UserID.HasValue) userId = Email.UserID.Value; if (Engine_ApplicationCache_Gateway.Settings.Email.Setup.Method == Email_Method_Enum.MsSqlDatabaseMail) { try { // Send database email Engine_Database.Send_Database_Email(Email.RecipientsList, Email.Subject, Email.Body, Email.FromAddress, Email.ReplyTo, Email.isHTML, Email.isContactUs, replyId, userId); } catch (Exception ee) { Error = ee.Message; return false; } } else { try { string email_name = Engine_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromDisplay; string email_address = Engine_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromAddress; if (!String.IsNullOrEmpty(Email.FromAddress)) { string[] splitter = Email.FromAddress.Trim().Split("<>".ToCharArray()); if (splitter.Length == 2) { email_name = splitter[0].Trim(); email_address = splitter[1].Trim(); } else { email_address = Email.FromAddress; } } MailMessage myMail = new MailMessage(Email.FromAddress, Email.RecipientsList) { Subject = Email.Subject, Body = Email.Body }; if (!String.IsNullOrEmpty(email_name)) { myMail.Sender = new MailAddress(email_address, email_name); } // Mail this SmtpClient client = new SmtpClient(Engine_ApplicationCache_Gateway.Settings.Email.Setup.SmtpServer, Engine_ApplicationCache_Gateway.Settings.Email.Setup.SmtpPort); client.Send(myMail); // Log this in the database Engine_Database.Log_Sent_Email(Email.FromAddress, Email.RecipientsList, Email.Subject, Email.Body, Email.isHTML, Email.isContactUs, -1); } catch (Exception ee) { Error = ee.Message; return false; } } return true; }
/// <summary> Sends one email to a user from the system including /// individual usage on items which are linked to the user </summary> /// <param name="UserID"> Primary key for whom to send the email </param> /// <param name="User_Name"> Name of the user to include in the email </param> /// <param name="User_Email"> Email address to use for this email </param> /// <param name="Year"> Year of statistics to highlight in the email </param> /// <param name="Month"> Month of statistics to highlight in the email </param> /// <param name="Number_Of_Items_To_Include"> Number of items to include in this email, in case the user has many, many items linked </param> /// <param name="System_URL"> Base URL to use for links to these items </param> /// <param name="System_Name"> Name of the SobekCM instance </param> /// <param name="FromAddress"> Address from which the email should be sent </param> /// <returns> TRUE if succesful, otherwise FALSE </returns> public static bool Send_Individual_Usage_Email(int UserID, string User_Name, string User_Email, int Year, int Month, int Number_Of_Items_To_Include, string System_URL, string System_Name, string FromAddress ) { // If no email body was loaded, use the default if (String.IsNullOrEmpty(emailBody)) emailBody = DEFAULT_EMAIL_BODY; try { // Get the item usage stats for this user on this month DataTable usageStats = Engine_Database.Get_User_Linked_Items_Stats(UserID, Month, Year, null); // Only continue if stats were returned if (usageStats != null) { // Use the data view DataView sortedView = new DataView(usageStats) {Sort = "Month_Hits DESC"}; // Keep track for a total row at the bottom int total_total_hits = 0; int total_month_hits = 0; // Build the string here StringBuilder itemStatsBuilder = new StringBuilder(); // Display the stats for each item int item_count = 0; foreach (DataRowView thisRow in sortedView) { if (item_count < Number_Of_Items_To_Include) { string bibid = thisRow["BibID"].ToString(); string vid = thisRow["VID"].ToString(); itemStatsBuilder.AppendLine("<strong><a href=\"" + System_URL + bibid + "/" + vid + "\">" + thisRow["Title"] + "</a></strong><br />"); itemStatsBuilder.AppendLine("<ul>"); itemStatsBuilder.AppendLine(" <li>Permanent Link: <a href=\"" + System_URL + bibid + "/" + vid + "\">" + System_URL + bibid + "/" + vid + "</a></li>"); itemStatsBuilder.AppendLine(" <li>Views"); itemStatsBuilder.AppendLine(" <ul>"); itemStatsBuilder.AppendLine(" <li>" + Month_From_Int(Month) + " " + Year + ": " + thisRow["Month_Hits"] + " views"); itemStatsBuilder.AppendLine(" <li>Total to date ( since " + Convert.ToDateTime(thisRow["CreateDate"]).ToShortDateString() + " ): " + thisRow["Total_Hits"] + " views"); itemStatsBuilder.AppendLine(" </ul>"); itemStatsBuilder.AppendLine(" </li>"); itemStatsBuilder.AppendLine("</ul>"); } // Also, add the values total_total_hits += Convert.ToInt32(thisRow["Total_Hits"]); total_month_hits += Convert.ToInt32(thisRow["Month_Hits"]); item_count++; } // Put some notes if there were more than 10 items if (item_count > Number_Of_Items_To_Include) itemStatsBuilder.Insert(0, TOO_MANY_ITEMS_MESSAGE.Replace("<%COUNT%>", item_count.ToString())); string email_body_user = emailBody.Replace("<%TOTAL%>", Number_To_String(total_total_hits)).Replace("<%MONTHLY%>", Number_To_String(total_month_hits)).Replace("<%ITEMS%>", itemStatsBuilder.ToString()).Replace("<%DATE%>", Month_From_Int(Month) + " " + Year).Replace("<%NAME%>", User_Name).Replace("<%SYSURL%>", System_URL).Replace("<%SYSNAME%>", System_Name).Replace("<%YEAR%>", Year.ToString()).Replace("<%MONTH%>", Month.ToString().PadLeft(2, '0')) + "<br /><br /><p>( " + Month_From_Int(Month) + " " + Year + " )</p>"; // Only send the email if there was actually usage this month though if (total_month_hits > 0) { // Send this email EmailInfo newEmail = new EmailInfo { FromAddress = FromAddress, RecipientsList = User_Email, isContactUs = false, isHTML = true, Subject = EMAIL_SUBJECT.Replace("<%DATE%>", Month_From_Int(Month) + " " + Year), Body = email_body_user }; string error; return Email_Helper.SendEmail(newEmail, out error); } } // No actual error here, just turns out no items were linked to this user return true; } catch (Exception) { return false; } }
private static bool HTML_Send_Email(string Recepient_List, string CcList, string Comments, string User_Name, string SobekCM_Instance_Name, SobekCM_Item Item, string URL, int UserID ) { try { // Collect the titles List<string> uniform_titles = new List<string>(); List<string> alternative_titles = new List<string>(); List<string> translated_titles = new List<string>(); List<string> abbreviated_titles = new List<string>(); if (Item.Bib_Info.Other_Titles_Count > 0) { foreach (Title_Info thisTitle in Item.Bib_Info.Other_Titles) { switch (thisTitle.Title_Type) { case Title_Type_Enum.UNSPECIFIED: case Title_Type_Enum.Alternative: alternative_titles.Add(thisTitle.ToString()); break; case Title_Type_Enum.Uniform: uniform_titles.Add(thisTitle.ToString()); break; case Title_Type_Enum.Translated: translated_titles.Add(thisTitle.ToString()); break; case Title_Type_Enum.Abbreviated: abbreviated_titles.Add(thisTitle.ToString()); break; } } } List<string> subjects = new List<string>(); List<string> hierGeo = new List<string>(); if (Item.Bib_Info.Subjects_Count > 0) { foreach (Subject_Info thisSubject in Item.Bib_Info.Subjects) { switch (thisSubject.Class_Type) { case Subject_Info_Type.Hierarchical_Spatial: hierGeo.Add(thisSubject.ToString()); break; default: subjects.Add(thisSubject.ToString()); break; } } } StringBuilder messageBuilder = new StringBuilder(); messageBuilder.AppendLine("<span style=\"font-family:Arial, Helvetica, sans-serif;\">"); if (Comments.Length > 0) { messageBuilder.AppendLine(User_Name + " wanted you to see this item on " + SobekCM_Instance_Name + " and included the following comments.<br /><br />\n"); messageBuilder.AppendLine(Comments.Replace("<", "(").Replace(">", ")").Replace("\"", """) + ".<br /><br />\n"); } else { messageBuilder.AppendLine(User_Name + " wanted you to see this item on " + SobekCM_Instance_Name + ".<br /><br />\n"); } messageBuilder.AppendLine("<table cellspacing=\"0px\" cellpadding=\"0px\">\n"); messageBuilder.AppendLine("<tr><td colspan=\"2\" style=\"background: black; color: white; font-family:Arial, Helvetica, sans-serif;\"><b>ITEM INFORMATION</b></td></tr>\n"); // Include the thumbnail, if one exists if (String.IsNullOrEmpty(Item.Behaviors.Main_Thumbnail)) messageBuilder.AppendLine("<tr>"); else messageBuilder.AppendLine("<tr valign=\"top\"><td><a href=\"" + URL + "\"><img src=\"" + UI_ApplicationCache_Gateway.Settings.Servers.Image_URL + Item.Web.AssocFilePath.Replace("\\", "/") + "/" + Item.Behaviors.Main_Thumbnail + "\" alt=\"BLOCKED THUMBNAIL IMAGE\" border=\"1px\" /></a></td>\n"); messageBuilder.AppendLine("<td>"); messageBuilder.AppendLine("<table style=\"font-family:Arial, Helvetica, sans-serif; font-size:smaller;\">"); messageBuilder.AppendLine("<tr><td>Title:</td><td><a href=\"" + URL + "\"><b>" + Item.Bib_Info.Main_Title + "</b></a></td></tr>"); if (( Item.Bib_Info.hasSeriesTitle ) && ( Item.Bib_Info.SeriesTitle.Title.Length > 0)) { messageBuilder.AppendLine("<tr><td>Series Title:</td><td>" + Item.Bib_Info.SeriesTitle + "</td></tr>\n"); } bool first_data = true; foreach (string title in uniform_titles) { if (first_data) { messageBuilder.AppendLine("<tr><td>Uniform Title:\t" + title + "</td></tr>\n"); first_data = false; } else { messageBuilder.AppendLine("<tr><td> </td><td>" + title + "</td></tr>\n"); } } first_data = true; foreach (string title in alternative_titles) { if (first_data) { messageBuilder.AppendLine("<tr><td>Alternate Title:</td><td>" + title + "</td></tr>\n"); first_data = false; } else { messageBuilder.AppendLine("<tr><td> </td><td>" + title.Replace("<i>", "") + "</td></tr>\n"); } } first_data = true; foreach (string title in translated_titles) { if (first_data) { messageBuilder.AppendLine("<tr><td>Translated Title:</td><td>" + title + "</td></tr>\n"); first_data = false; } else { messageBuilder.AppendLine("<tr><td> </td><td>" + title + "</td></tr>\n"); } } first_data = true; foreach (string title in abbreviated_titles) { if (first_data) { messageBuilder.AppendLine("<tr><td>Abbreviated Title:</td><td>" + title + "</td></tr>\n"); first_data = false; } else { messageBuilder.AppendLine("<tr><td> </td><td>" + title + "</td></tr>\n"); } } if (( Item.Bib_Info.hasMainEntityName ) && ( Item.Bib_Info.Main_Entity_Name.hasData)) { messageBuilder.AppendLine("<tr><td>Creator:</td><td>" + Item.Bib_Info.Main_Entity_Name + "</td></tr>\n"); first_data = false; } if (Item.Bib_Info.Names_Count > 0) { foreach (Name_Info thisName in Item.Bib_Info.Names) { if (first_data) { messageBuilder.AppendLine("<tr><td>Creator:</td><td>" + thisName + "</td></tr>\n"); first_data = false; } else { messageBuilder.AppendLine("<tr><td> </td><td>" + thisName + "</td></tr>\n"); } } } if (Item.Bib_Info.Publishers_Count > 0) { first_data = true; foreach (Publisher_Info thisPublisher in Item.Bib_Info.Publishers) { if (first_data) { messageBuilder.AppendLine("<tr><td>Publisher:</td><td>" + thisPublisher + "</td></tr>\n"); first_data = false; } else { messageBuilder.AppendLine("<tr><td> </td><td>" + thisPublisher + "</td></tr>\n"); } } } if (Item.Bib_Info.Origin_Info.Date_Issued.Length > 0) { messageBuilder.AppendLine("<tr><td>Date:</td><td>" + Item.Bib_Info.Origin_Info.Date_Issued + "</td></tr>\n"); } else { if (Item.Bib_Info.Origin_Info.MARC_DateIssued.Length > 0) { messageBuilder.AppendLine("<tr><td>Date:</td><td>" + Item.Bib_Info.Origin_Info.MARC_DateIssued + "</td></tr>\n"); } } if (Item.Bib_Info.Original_Description.Extent.Length > 0) { messageBuilder.AppendLine("<tr><td>Description:</td><td>" + Item.Bib_Info.Original_Description.Extent + " ( " + Item.Bib_Info.SobekCM_Type + " )</td></tr>\n"); } else { messageBuilder.AppendLine("<tr><td>Description:</td><td>" + Item.Bib_Info.SobekCM_Type_String + "</td></tr>\n"); } if (subjects.Count > 0) { first_data = true; foreach (string thisSubject in subjects) { if (first_data) { messageBuilder.AppendLine("<tr><td>Subject:</td><td>" + thisSubject + "</td></tr>\n"); first_data = false; } else { messageBuilder.AppendLine("<tr><td> </td><td>" + thisSubject + "</td></tr>\n"); } } } if (Item.Bib_Info.Genres_Count > 0) { first_data = true; foreach (Genre_Info thisGenre in Item.Bib_Info.Genres) { if (first_data) { messageBuilder.AppendLine("<tr><td>Genre:</td><td>" + thisGenre + "</td></tr>\n"); first_data = false; } else { messageBuilder.AppendLine("<tr><td> </td><td>" + thisGenre + "</td></tr>\n"); } } } if (hierGeo.Count > 0) { first_data = true; foreach (string thisSubject in hierGeo) { if (first_data) { messageBuilder.AppendLine("<tr><td>Spatial Coverage:</td><td>" + thisSubject + "</td></tr>\n"); first_data = false; } else { messageBuilder.AppendLine("<tr><td> </td><td>" + thisSubject + "</td></tr>\n"); } } } if (Item.Bib_Info.Access_Condition.Text.Length > 0) { messageBuilder.AppendLine("<tr><td>Rights:</td><td>" + Item.Bib_Info.Access_Condition.Text + "</td></tr>\n"); } messageBuilder.AppendLine("</table>"); messageBuilder.AppendLine("</td></tr></table>"); messageBuilder.AppendLine("</span>\n"); string[] email_recepients = Recepient_List.Split(";,".ToCharArray()); string subject = Item.Bib_Info.Main_Title.ToString().Replace(""", "\""); if (Item.Bib_Info.Main_Title.Title.Length > 40) { subject = Item.Bib_Info.Main_Title.ToString().Substring(0, 35).Replace(""", "\"") + "..."; } int error_count = 0; foreach (string thisReceipient in email_recepients) { EmailInfo newEmail = new EmailInfo { Body = messageBuilder.ToString(), isContactUs = false, isHTML = true, Subject = subject, RecipientsList = thisReceipient, FromAddress = SobekCM_Instance_Name + " <" + UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromAddress + ">", UserID = UserID }; if (! String.IsNullOrEmpty(UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromDisplay)) newEmail.FromAddress = UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromDisplay + " <" + UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromAddress + ">"; if (CcList.Length > 0) newEmail.RecipientsList = thisReceipient.Trim() + "," + CcList; string error; if (!Email_Helper.SendEmail(newEmail, out error)) error_count++; } return error_count <= 0; } catch { return false; } }
private static bool Text_Send_Email(string Recepient_List, string CcList, string Comments, string User_Name, string SobekCM_Instance_Name, SobekCM_Item Item, string URL, int UserID ) { try { // Collect the titles List<string> uniform_titles = new List<string>(); List<string> alternative_titles = new List<string>(); List<string> translated_titles = new List<string>(); List<string> abbreviated_titles = new List<string>(); if (Item.Bib_Info.Other_Titles_Count > 0) { foreach (Title_Info thisTitle in Item.Bib_Info.Other_Titles) { switch (thisTitle.Title_Type) { case Title_Type_Enum.UNSPECIFIED: case Title_Type_Enum.Alternative: alternative_titles.Add(thisTitle.ToString()); break; case Title_Type_Enum.Uniform: uniform_titles.Add(thisTitle.ToString()); break; case Title_Type_Enum.Translated: translated_titles.Add(thisTitle.ToString()); break; case Title_Type_Enum.Abbreviated: abbreviated_titles.Add(thisTitle.ToString()); break; } } } List<string> subjects = new List<string>(); List<string> hierGeo = new List<string>(); if (Item.Bib_Info.Subjects_Count > 0) { foreach (Subject_Info thisSubject in Item.Bib_Info.Subjects) { switch (thisSubject.Class_Type) { case Subject_Info_Type.Hierarchical_Spatial: hierGeo.Add(thisSubject.ToString()); break; default: subjects.Add(thisSubject.ToString()); break; } } } StringBuilder messageBuilder = new StringBuilder(); if (Comments.Length > 0) { messageBuilder.Append(User_Name + " wanted you to see this item on " + SobekCM_Instance_Name + " and included the following comments:\n\n"); messageBuilder.Append("\"" + Comments + "\"\n\n"); } else { messageBuilder.Append(User_Name + " wanted you to see this item on " + SobekCM_Instance_Name + ".\n\n"); } messageBuilder.Append("ITEM INFORMATION\n"); messageBuilder.Append("------------------------------------------------------\n"); messageBuilder.Append("\tURL:\t\t\t" + URL + "\n"); messageBuilder.Append("\tTitle:\t\t" + Item.Bib_Info.Main_Title.ToString().Replace(""", "\"") + "\n"); if (( Item.Bib_Info.hasSeriesTitle ) && ( Item.Bib_Info.SeriesTitle.Title.Length > 0)) { messageBuilder.Append("\tSeries Title:\t" + Item.Bib_Info.SeriesTitle.ToString().Replace(""", "\"") + "\n"); } bool first_data = true; foreach (string title in uniform_titles) { if (first_data) { messageBuilder.Append("\tUniform Title:\t" + title.Replace("<i>", "").Replace("</i>", "").Replace(""", "\"") + "\n"); first_data = false; } else { messageBuilder.Append("\t\t\t\t" + title.Replace("<i>", "").Replace("</i>", "").Replace(""", "\"") + "\n"); } } first_data = true; foreach (string title in alternative_titles) { if (first_data) { messageBuilder.Append("\tAlternate Title:\t" + title.Replace("<i>", "").Replace("</i>", "").Replace(""", "\"") + "\n"); first_data = false; } else { messageBuilder.Append("\t\t\t\t" + title.Replace("<i>", "").Replace("</i>", "").Replace(""", "\"") + "\n"); } } first_data = true; foreach (string title in translated_titles) { if (first_data) { messageBuilder.Append("\tTranslated Title: " + title.Replace("<i>", "").Replace("</i>", "").Replace(""", "\"") + "\n"); first_data = false; } else { messageBuilder.Append("\t\t\t\t" + title.Replace("<i>", "").Replace("</i>", "").Replace(""", "\"") + "\n"); } } first_data = true; foreach (string title in abbreviated_titles) { if (first_data) { messageBuilder.Append("\tAbbreviated Title:" + title.Replace("<i>", "").Replace("</i>", "").Replace(""", "\"") + "\n"); first_data = false; } else { messageBuilder.Append("\t\t\t\t" + title.Replace("<i>", "").Replace("</i>", "").Replace(""", "\"") + "\n"); } } if ((Item.Bib_Info.hasMainEntityName) && (Item.Bib_Info.Main_Entity_Name.hasData)) { messageBuilder.Append("\tCreator:\t\t" + Item.Bib_Info.Main_Entity_Name.ToString().Replace("<i>", "").Replace("</i>", "").Replace(""", "\"") + "\n"); first_data = false; } if (Item.Bib_Info.Names_Count > 0) { foreach (Name_Info thisName in Item.Bib_Info.Names) { if (first_data) { messageBuilder.Append("\tCreator:\t\t" + thisName.ToString().Replace("<i>", "").Replace("</i>", "").Replace(""", "\"") + "\n"); first_data = false; } else { messageBuilder.Append("\t\t\t\t" + thisName.ToString().Replace("<i>", "").Replace("</i>", "").Replace(""", "\"") + "\n"); } } } if (Item.Bib_Info.Publishers_Count > 0) { first_data = true; foreach (Publisher_Info thisPublisher in Item.Bib_Info.Publishers) { if (first_data) { messageBuilder.Append("\tPublisher:\t\t" + thisPublisher + "\n"); first_data = false; } else { messageBuilder.Append("\t\t\t\t" + thisPublisher + "\n"); } } } if (Item.Bib_Info.Origin_Info.Date_Issued.Length > 0) { messageBuilder.Append("\tDate:\t\t\t" + Item.Bib_Info.Origin_Info.Date_Issued + "\n"); } else { if (Item.Bib_Info.Origin_Info.MARC_DateIssued.Length > 0) { messageBuilder.Append("\tDate:\t\t\t" + Item.Bib_Info.Origin_Info.MARC_DateIssued + "\n"); } } if (Item.Bib_Info.Original_Description.Extent.Length > 0) { messageBuilder.Append("\tDescription:\t" + Item.Bib_Info.Original_Description.Extent + " ( " + Item.Bib_Info.SobekCM_Type_String + " )\n"); } else { messageBuilder.Append("\tDescription:\t" + Item.Bib_Info.SobekCM_Type_String + "\n"); } if (subjects.Count > 0) { first_data = true; foreach (string thisSubject in subjects) { if (first_data) { messageBuilder.Append("\tSubject:\t\t" + thisSubject.Replace("<i>", "").Replace("</i>", "") + "\n"); first_data = false; } else { messageBuilder.Append("\t\t\t\t" + thisSubject.Replace("<i>", "").Replace("</i>", "") + "\n"); } } } if (Item.Bib_Info.Genres_Count > 0) { first_data = true; foreach (Genre_Info thisGenre in Item.Bib_Info.Genres) { if (first_data) { messageBuilder.Append("\tGenre:\t\t" + thisGenre.ToString().Replace("<i>", "").Replace("</i>", "") + "\n"); first_data = false; } else { messageBuilder.Append("\t\t\t\t" + thisGenre.ToString().Replace("<i>", "").Replace("</i>", "") + "\n"); } } } if (hierGeo.Count > 0) { first_data = true; foreach (string thisSubject in hierGeo) { if (first_data) { messageBuilder.Append("\tSpatial Coverage: " + thisSubject.Replace("<i>", "").Replace("</i>", "") + "\n"); first_data = false; } else { messageBuilder.Append("\t\t\t\t" + thisSubject.Replace("<i>", "").Replace("</i>", "") + "\n"); } } } if (Item.Bib_Info.Access_Condition.Text.Length > 0) { messageBuilder.Append("\tRights:\t\t" + Item.Bib_Info.Access_Condition.Text + "\n"); } messageBuilder.Append("</span>\n"); string[] email_recepients = Recepient_List.Split(";,".ToCharArray()); string subject = Item.Bib_Info.Main_Title.ToString().Replace(""", "\""); if (Item.Bib_Info.Main_Title.Title.Length > 40) { subject = Item.Bib_Info.Main_Title.ToString().Substring(0, 35).Replace(""", "\"") + "..."; } int error_count = 0; foreach (string thisReceipient in email_recepients) { EmailInfo newEmail = new EmailInfo { Body = messageBuilder.ToString(), isContactUs = false, isHTML = false, Subject = subject, RecipientsList = thisReceipient, FromAddress = SobekCM_Instance_Name + " <" + UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromAddress + ">", UserID = UserID }; if (!String.IsNullOrEmpty(UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromDisplay)) newEmail.FromAddress = UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromDisplay + " <" + UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromAddress + ">"; if (CcList.Length > 0) newEmail.RecipientsList = thisReceipient.Trim() + "," + CcList; string error; if (!Email_Helper.SendEmail(newEmail, out error)) error_count++; } return error_count <= 0; } catch { return false; } }