public ActionResult Image(int id = 0) { if (id != 0) { var email = db.BroadcastingEmails.SingleOrDefault(e => e.Id == id); if (email != null) { EmailTracking emailTracking = new EmailTracking(); emailTracking.MessageId = id; emailTracking.IP = Request.UserHostAddress; emailTracking.Created = DateTime.Now; db.EmailTrackings.Add(emailTracking); db.SaveChanges(); } } var dir = Server.MapPath("~/Images"); var path = System.IO.Path.Combine(dir, "1x1_pixel.jpg"); return(base.File(path, "image/jpeg")); }
public void SendInputFileEmail(Application info, Int32 runNumberID, List <string> emailList) { try { SingletonLogger.Instance.Debug("Fetching email template for TOKEN = " + "DOWNLOAD_FILE"); EmailTemplate template = _emailTemplateRepository.EmailTemplate(x => x.ClientId == info.ClientId && x.ApplicationId == info.ApplicationId && x.EmailToken == "{{DOWNLOAD_FILE}}"); if (template != null) { SingletonLogger.Instance.Debug("templateID = " + template.EmailTemplateId + " runId " + runNumberID); EmailTracking tracking = new EmailTracking() { RunNumberId = runNumberID, FromEmailId = template.EmailFromSmtpId.ToString(), EmailTemplateId = template.EmailTemplateId, Subjects = template.Subject, Body = template.Body, EmailStatus = (int)EmailStatusType.Ready, EmailToIds = template.EmailToIds, EmailCcIds = template.EmailCcIds }; SingletonLogger.Instance.Debug("trackingID = " + tracking.EmailTrackingId); if (tracking != null) { tracking.SentDate = DateTime.Now; tracking.CreatedAt = DateTimeOffset.Now; tracking.Body = tracking.Body.Replace("{{FILE_LIST}}", CreateTable(emailList)); tracking.Body = tracking.Body.Replace("{{FILE_NAME}}", CreateTable(emailList)); tracking.Subjects = tracking.Subjects.Replace("{{APPLICATION_NAME}}", info.Name); tracking.Body = tracking.Body.Replace("{{APPLICATION_NAME}}", info.Name); tracking.Status = true; if (_emailTrackingRepository.Save(tracking) != 0) { SingletonLogger.Instance.Error("Error occured while email saving to email tracking."); } } } else { SingletonLogger.Instance.Debug("Email Template not found in database for TOKEN = " + "DOWNLOAD_FILE"); } } catch (Exception ex) { SingletonLogger.Instance.Error("Error occured while sending email about file download = " + ex.Message + " " + ex.InnerException != null?ex.InnerException.Message:"" + ex.ToString() + " " + ex.StackTrace); } }
public void SendInputFileEmail(int runComponentId, string component, string runNumber, string token, string message = "Success") { try { SingletonLogger.Instance.Debug("Fetching email template for TOKEN = " + token); Application appInfo = _applicationRepository.Find(_runNumberRepository.GetApplicationIdByRunNumber(runNumber)); int componentId = _runComponentRepository.Find(runComponentId).ComponentId; EmailTemplate template = _emailTemplateRepository.EmailTemplate(x => x.ClientId == appInfo.ClientId && x.ApplicationId == appInfo.ApplicationId && x.ApplicationComponentId == componentId && x.EmailToken == token); if (template != null) { EmailTracking tracking = new EmailTracking() { RunNumberId = _runNumberRepository.GetRunNumberIdByRunNumber(runNumber), FromEmailId = template.EmailFromSmtpId.ToString(), EmailTemplateId = template.EmailTemplateId, Subjects = template.Subject, Body = template.Body, EmailStatus = (int)EmailStatusType.Ready }; if (tracking != null) { tracking.SentDate = DateTime.Now; tracking.Body = tracking.Body.Replace("{{CLIENT_NAME}}", appInfo.ClientId.ToString()); tracking.Body = tracking.Body.Replace("{{APPLICATION_NAME}}", appInfo.Name).Replace("{{COMPONENT_NAME}}", component); tracking.Body = tracking.Body.Replace("{{MESSAGE}}", message); tracking.Subjects = tracking.Subjects.Replace("{{COMPONENT_NAME}}", component).Replace("{{APPLICATION_NAME}}", appInfo.Name).Replace("{{CLIENT_NAME}}", appInfo.ClientId.ToString()); if (_emailTrackingRepository.Save(tracking) != 0) { SingletonLogger.Instance.Error("Error occured while email saving to email tracking."); } } } else { SingletonLogger.Instance.Debug("Email Template not found in database for TOKEN = " + token); } } catch (Exception ex) { SingletonLogger.Instance.Error("Error occured while sending email about file download = " + ex.Message); } }
private MailMessage BuidMailMessage(ClubCloud_Vereniging vereniging) { MailMessage message = null; XDocument xmlInputData = new XDocument(new XElement("Properties")); XElement elements = new XElement("Elements", new object[] { new XElement("HEADER"), new XElement("FEATURED_AREA"), new XElement("FULL_WIDTH_COLUMN"), new XElement("INTRO"), new XElement("HALF_COLUMN_FEATURES"), new XElement("HALF_COLUMN_TOP_IMAGE"), new XElement("ONE_THIRD_TWO_THIRD_COLUMN_LEFT_IMAGE"), new XElement("TWO_THIRD_ONE_THIRD_COLUMN_RIGHT_IMAGE"), new XElement("CENTRECOURT"), new XElement("BOTTOM_CALL_TO_ACTION"), new XElement("FOOTER") }); xmlInputData.Root.Add(elements); xmlInputData.Root.Add(vereniging.ToXElement <ClubCloud_Vereniging>()); EmailTracking track = new EmailTracking { CampaignName = "Introductie", CampaignSource = "Nieuwsbrief", CampagneMedium = "email", ClientId = vereniging.Id, RecipientId = vereniging.Nummer, TrackingId = "UA-9934149-20", CampagneContent = "Introductie", CampagneTerm = "Introductie" }; xmlInputData.Root.Add(track.ToXElement <EmailTracking>()); XElement content = new XElement("Content", new XElement("Subject", string.Format("ClubCloud : De slimme keuze voor {0}", vereniging.Naam))); xmlInputData.Root.Add(content); SPSecurity.RunWithElevatedPrivileges(delegate() { try { using (SPSite currentSite = new SPSite(SPContext.Current.Site.ID, SPUrlZone.Internet)) { using (SPWeb web = currentSite.OpenWeb(SPContext.Current.Web.ID)) { SPDocumentLibrary SiteAssets = null; SPDocumentLibrary SitePages = null; SPFolder Templates = null; SPFolder Online = null; SPFile Aanmelden = null; SPFile Webversion = null; SPItem WebversionItem = null; XmlReader template = null; SPList assets = web.Lists.TryGetList("SiteAssets"); if (assets == null) { assets = web.Lists.TryGetList("Siteactiva"); } if (assets != null) { SiteAssets = (SPDocumentLibrary)assets; } if (SiteAssets != null) { Templates = SiteAssets.RootFolder.SubFolders["Templates"]; } SPList pages = web.Lists.TryGetList("SitePages"); if (pages == null) { pages = web.Lists.TryGetList("Sitepagina's"); } SPQuery query = new SPQuery(); query.Query = string.Format("<Where><Eq><FieldRef Name=\"Title\" /><Value Type=\"Text\">ClubCloud : De slimme keuze voor {0}</Value></Eq></Where>", vereniging.Naam); query.RowLimit = 1; query.ViewFields = @"<FieldRef Name=""Title"" />"; query.ViewAttributes = @"Scope=""Recursive"""; SPListItemCollection items = pages.GetItems(query); if (items.Count > 0) { throw new SPDuplicateObjectException("Club already mailed", new Exception("Club already mailed")); } if (pages != null) { SitePages = (SPDocumentLibrary)pages; } if (SitePages != null) { Online = SitePages.RootFolder.SubFolders["Online"]; } if (Templates != null && Templates.Exists) { Aanmelden = Templates.Files["template.xsl"]; } if (Aanmelden != null && Aanmelden.Exists) { template = XmlReader.Create(Aanmelden.OpenBinaryStream()); } if (template == null) { throw new FileNotFoundException("Template not Found", Aanmelden.Url); } string body = GenerateEmailBody(template, xmlInputData); web.AllowUnsafeUpdates = true; if (Online != null && Online.Exists) { Webversion = Online.Files.Add(Guid.NewGuid() + ".aspx", System.Text.Encoding.UTF8.GetBytes(body), true); WebversionItem = pages.GetItemByUniqueId(Webversion.UniqueId); WebversionItem["Title"] = string.Format("ClubCloud : De slimme keuze voor {0}", vereniging.Naam); WebversionItem.Update(); } if (Webversion != null && Webversion.Exists) { XElement online = new XElement("Online", new object[] { new XElement("WebVersion", string.Format("{0}/{1}", currentSite.Url, Webversion.Url)) }); xmlInputData.Root.Add(online); } if (Aanmelden != null && Aanmelden.Exists) { template = XmlReader.Create(Aanmelden.OpenBinaryStream()); } body = GenerateEmailBody(template, xmlInputData); web.AllowUnsafeUpdates = false; message = Email.CreateMailMessage(body); } } } catch (Exception ex) { Logger.WriteLog(Logger.Category.Unexpected, ex.Source, ex.Message); message = null; } }); return(message); }
protected void wzd_aanmelden_FinishButtonClick(object sender, WizardNavigationEventArgs e) { //using (SPLongOperation operation = new SPLongOperation(this.Page)) //{ // operation.Begin(); using (new SPMonitoredScope("Mailing SendMail")) { try { XDocument xmlInputData = new XDocument(new XElement("Properties")); XElement elements = new XElement("Elements", new object[] { new XElement("HEADER"), new XElement("FEATURED_AREA"), new XElement("VERENIGING"), new XElement("GEBRUIKER"), new XElement("OPMERKINGEN"), new XElement("BOTTOM_CALL_TO_ACTION"), new XElement("FOOTER") }); xmlInputData.Root.Add(elements); ClubCloud_Vereniging vereniging = new ClubCloud_Vereniging(); string verenigingsnummer = tbx_verenigingsnummer.Text; string number = string.Empty; int parsed = 0; if (verenigingsnummer.IndexOf('-') > 0) { number = verenigingsnummer.Split('-')[0].Trim(); } else { number = verenigingsnummer; } if (int.TryParse(number, out parsed)) { try { vereniging = Client.GetVerenigingByNummer("00000000", parsed.ToString(), false); } catch (Exception ex) { Logger.WriteLog(Logger.Category.Unexpected, ex.Source, ex.Message); } } if (vereniging == null) { vereniging = new ClubCloud_Vereniging(); } if (vereniging.Nummer != number) { vereniging.Nummer = number; } TextBox vereniging_naam = (TextBox)fvw_vereniging.FindControl("Naam"); string verenigingnaam = vereniging_naam.Text; if (vereniging.Naam != vereniging_naam.Text && !string.IsNullOrWhiteSpace(vereniging_naam.Text)) { vereniging.Naam = vereniging_naam.Text; } TextBox vereniging_KvKNummer = (TextBox)fvw_vereniging.FindControl("KvKNummer"); string verenigingkvknummer = vereniging_KvKNummer.Text; if (vereniging.KvKnummer != vereniging_KvKNummer.Text && !string.IsNullOrWhiteSpace(vereniging_KvKNummer.Text)) { vereniging.KvKnummer = vereniging_KvKNummer.Text; } TextBox vereniging_KvKPlaats = (TextBox)fvw_vereniging.FindControl("KvKPlaats"); string verenigingkvkplaats = vereniging_KvKPlaats.Text; if (vereniging.KvKplaats != vereniging_KvKPlaats.Text && !string.IsNullOrWhiteSpace(vereniging_KvKPlaats.Text)) { vereniging.KvKplaats = vereniging_KvKPlaats.Text; } TextBox vereniging_BankNummer = (TextBox)fvw_vereniging.FindControl("BankNummer"); string verenigingbanknummer = vereniging_BankNummer.Text; if (vereniging.BankNummer != vereniging_BankNummer.Text && !string.IsNullOrWhiteSpace(vereniging_BankNummer.Text)) { vereniging.BankNummer = vereniging_BankNummer.Text; } TextBox vereniging_BankIban = (TextBox)fvw_vereniging.FindControl("BankIban"); string verenigingbankiban = vereniging_BankIban.Text; if (vereniging.BankIban != vereniging_BankIban.Text && !string.IsNullOrWhiteSpace(vereniging_BankIban.Text)) { vereniging.BankIban = vereniging_BankIban.Text; } TextBox vereniging_BankPlaats = (TextBox)fvw_vereniging.FindControl("BankPlaats"); string verenigingbankplaats = vereniging_BankPlaats.Text; if (vereniging.BankPlaats != vereniging_BankPlaats.Text && !string.IsNullOrWhiteSpace(vereniging_BankPlaats.Text)) { vereniging.BankPlaats = vereniging_BankPlaats.Text; } TextBox vereniging_TelefoonOverdag = (TextBox)fvw_vereniging.FindControl("TelefoonOverdag"); string verenigingtelefoonoverdag = vereniging_TelefoonOverdag.Text; if (vereniging.TelefoonOverdag != vereniging_TelefoonOverdag.Text && !string.IsNullOrWhiteSpace(vereniging_TelefoonOverdag.Text)) { vereniging.TelefoonOverdag = vereniging_TelefoonOverdag.Text; } TextBox vereniging_TelefoonAvond = (TextBox)fvw_vereniging.FindControl("TelefoonAvond"); string verenigingtelefoonavond = vereniging_TelefoonAvond.Text; if (vereniging.TelefoonAvond != vereniging_TelefoonAvond.Text && !string.IsNullOrWhiteSpace(vereniging_TelefoonAvond.Text)) { vereniging.TelefoonAvond = vereniging_TelefoonAvond.Text; } TextBox vereniging_Email = (TextBox)fvw_vereniging.FindControl("Email"); string verenigingemail = vereniging_Email.Text; if (vereniging.EmailKNLTB != vereniging_Email.Text && !string.IsNullOrWhiteSpace(vereniging_Email.Text)) { vereniging.EmailKNLTB = vereniging_Email.Text; } xmlInputData.Root.Add(vereniging.ToXElement <ClubCloud_Vereniging>()); ClubCloud_Gebruiker gebruiker = new ClubCloud_Gebruiker(); TextBox persoon_knltb = (TextBox)fvw_persoon.FindControl("KNLTBNummer"); string persoonknltb = persoon_knltb.Text; string lm = string.Empty; parsed = 0; if (int.TryParse(persoonknltb, out parsed)) { lm = "luckyme"; } /* * { * try * { * gebruiker = Client.GetGebruikerByNummer("00000000", vereniging.Id, parsed.ToString(), false); * } * catch (Exception ex) * { * Logger.WriteLog(Logger.Category.Unexpected, ex.Source, ex.Message); * } * } */ if (gebruiker == null) { gebruiker = new ClubCloud_Gebruiker(); } if (gebruiker.Bondsnummer != parsed.ToString()) { gebruiker.Bondsnummer = parsed.ToString(); } TextBox persoon_naam = (TextBox)fvw_persoon.FindControl("Naam"); string persoonnaam = persoon_naam.Text; if (gebruiker.Volledigenaam != persoon_naam.Text && !string.IsNullOrWhiteSpace(persoon_naam.Text)) { gebruiker.Volledigenaam = persoon_naam.Text; } TextBox persoon_TelefoonOverdag = (TextBox)fvw_persoon.FindControl("TelefoonOverdag"); string persoontelefoonoverdag = persoon_TelefoonOverdag.Text; if (gebruiker.TelefoonOverdag != persoon_TelefoonOverdag.Text && !string.IsNullOrWhiteSpace(persoon_TelefoonOverdag.Text)) { gebruiker.TelefoonOverdag = persoon_TelefoonOverdag.Text; } TextBox persoon_TelefoonAvond = (TextBox)fvw_persoon.FindControl("TelefoonAvond"); string persoontelefoonavond = persoon_TelefoonAvond.Text; if (gebruiker.TelefoonAvond != persoon_TelefoonAvond.Text && !string.IsNullOrWhiteSpace(persoon_TelefoonAvond.Text)) { gebruiker.TelefoonAvond = persoon_TelefoonAvond.Text; } TextBox persoon_Email = (TextBox)fvw_persoon.FindControl("Email"); string persoonemail = persoon_Email.Text; if (gebruiker.EmailKNLTB != persoon_Email.Text && !string.IsNullOrWhiteSpace(persoon_Email.Text)) { gebruiker.EmailKNLTB = persoon_Email.Text; } xmlInputData.Root.Add(gebruiker.ToXElement <ClubCloud_Gebruiker>()); XElement aanmelden = new XElement("Aanmelden", new object[] { new XElement("Opmerkingen", opmerkingen.Text), new XElement("Akkoord", akkoord.Checked), new XElement("Datum", DateTime.Now.ToString()), new XElement("IP", GetIPAddress()) }); xmlInputData.Root.Add(aanmelden); EmailTracking tracking = new EmailTracking { CampaignName = "Aanmelden", CampaignSource = "WebSite", ClientId = vereniging.Id, RecipientId = vereniging.Nummer, TrackingId = "UA-9934149-20", CampagneContent = "aanmelden", CampagneMedium = "email", CampagneTerm = "aanmelden" }; xmlInputData.Root.Add(tracking.ToXElement <EmailTracking>()); XElement content = new XElement("Content", new XElement("Subject", string.Format("Aanmelden bij ClubCloud voor {0} ({1})", vereniging.Naam, vereniging.Nummer))); xmlInputData.Root.Add(content); SPSecurity.RunWithElevatedPrivileges(delegate() { try { using (SPSite currentSite = new SPSite(SPContext.Current.Site.ID, SPUrlZone.Internet)) { using (SPWeb web = currentSite.OpenWeb(SPContext.Current.Web.ID)) { SPDocumentLibrary SiteAssets = null; SPDocumentLibrary SitePages = null; SPFolder Templates = null; SPFolder Online = null; SPFile Aanmelden = null; SPFile Webversion = null; SPItem WebversionItem = null; XmlReader template = null; SPList assets = web.Lists.TryGetList("SiteAssets"); if (assets == null) { assets = web.Lists.TryGetList("Siteactiva"); } if (assets != null) { SiteAssets = (SPDocumentLibrary)assets; } if (SiteAssets != null) { Templates = SiteAssets.RootFolder.SubFolders["Templates"]; } SPList pages = web.Lists.TryGetList("SitePages"); if (pages == null) { pages = web.Lists.TryGetList("Sitepagina's"); } if (pages != null) { SitePages = (SPDocumentLibrary)pages; } if (SitePages != null) { Online = SitePages.RootFolder.SubFolders["Online"]; } if (Templates != null && Templates.Exists) { Aanmelden = Templates.Files["aanmelden.xsl"]; } if (Aanmelden != null && Aanmelden.Exists) { template = XmlReader.Create(Aanmelden.OpenBinaryStream()); } if (template == null) { throw new FileNotFoundException("Template not Found", Aanmelden.Url); } string body = GenerateEmailBody(template, xmlInputData); web.AllowUnsafeUpdates = true; if (Online != null && Online.Exists) { Webversion = Online.Files.Add(Guid.NewGuid() + ".aspx", System.Text.Encoding.UTF8.GetBytes(body), true); WebversionItem = pages.GetItemByUniqueId(Webversion.UniqueId); WebversionItem["Title"] = string.Format("Aanmelden bij ClubCloud voor {0} ({1})", vereniging.Naam, vereniging.Nummer); WebversionItem.Update(); } if (Webversion != null && Webversion.Exists) { XElement online = new XElement("Online", new object[] { new XElement("WebVersion", string.Format("{0}/{1}", currentSite.Url, Webversion.Url)) }); xmlInputData.Root.Add(online); } if (Aanmelden != null && Aanmelden.Exists) { template = XmlReader.Create(Aanmelden.OpenBinaryStream()); } body = GenerateEmailBody(template, xmlInputData); web.AllowUnsafeUpdates = false; MailMessage message = Email.CreateMailMessage(body); MailAddress tovereniging = new MailAddress(vereniging.EmailKNLTB, vereniging.Naam, Encoding.UTF8); message.To.Add(tovereniging); MailAddress topersoon = new MailAddress(gebruiker.EmailKNLTB, gebruiker.Volledigenaam, Encoding.UTF8); message.To.Add(topersoon); message.CC.Add(new MailAddress("*****@*****.**", "Aanmelden bij ClubCloud")); message.From = new MailAddress("*****@*****.**", "Aanmelden bij ClubCloud"); message.Subject = string.Format("Aanmelden bij ClubCloud voor {0}({1})", vereniging.Naam, vereniging.Nummer); message.Priority = MailPriority.Normal; message.ReplyToList.Add(new MailAddress("*****@*****.**", "Aanmelden bij ClubCloud")); message.Sender = new MailAddress("*****@*****.**", "Aanmelden bij ClubCloud"); SmtpClient client = new SmtpClient(ZimbraConfiguration.Server.SendMailHost, zimbraconfiguration.Server.SendMailPort); client.Credentials = new System.Net.NetworkCredential(ZimbraConfiguration.Server.SendMailUserName, ZimbraConfiguration.Server.SendMailPassword); client.DeliveryMethod = SmtpDeliveryMethod.Network; message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure | DeliveryNotificationOptions.OnSuccess | DeliveryNotificationOptions.Delay; Email.Send(message, client); } } } catch (Exception ex) { Logger.WriteLog(Logger.Category.Unexpected, ex.Source, ex.Message); } }); } catch (Exception ex) { Logger.WriteLog(Logger.Category.Unexpected, ex.Source, ex.Message); } } //operation.End("bedankt.aspx"); //} }