protected void cmdSaveNewRecipientList_ClickHandler(object sender, EventArgs e) { string name = txtRecipientListName.Text; string desc = txtRecipientListDesc.Text; if (string.IsNullOrEmpty(name)) { ShowError("Name cannot be empty"); return; } // Create and Save RecipientList newList = new RecipientList((RecipientListType)Int32.Parse(dropListRecipientTypes.SelectedValue), name, desc); try { newList.Save(); } catch (ArgumentException ex) { ShowError(ex.Message.ToString()); return; } //Redirect to the new recipient list page if (newList.Id != 0) { Response.Redirect(BVNetwork.EPiSendMail.Configuration.NewsLetterConfiguration.GetModuleBaseDir() + "/plugin/recipientlists/listedit.aspx?recipientlistid=" + newList.Id); } else { ShowError("Something went wrong saving new recipient list"); } }
public List <string> ValidateRecipientList(int recipientList, int blockList) { _log.Debug("Validating recipient list {0}, adding to block list {1}", recipientList, blockList); RecipientList list = RecipientList.Load(recipientList); RecipientList blocked = RecipientList.Load(blockList); MailSenderMailgun sender = new MailSenderMailgun(); List <string> result = null; try { result = sender.ValidateRecipientList(list, blocked); } catch (Exception e) { _log.Error("Error validating recipent list", e); throw new HttpResponseException( Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Cannot validate emails: " + e.Message)); } if (result == null) { throw new HttpResponseException( Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "An error occured during parsing, please inspect the logs.")); } return(result); }
public async void TestGetRecipientList() { var options = new DbContextOptionsBuilder <MessageContext>() .UseInMemoryDatabase(databaseName: "p3MessageService") .Options; using (var context = new MessageContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); Repo r = new Repo(context, new NullLogger <Repo>()); Mapper map = new Mapper(); Logic logic = new Logic(r, map, new NullLogger <Repo>()); MessageController messageController = new MessageController(logic, null); var recipientList = new RecipientList { RecipientListID = Guid.NewGuid(), RecipientID = "625325433" }; r.RecipientLists.Add(recipientList); await r.CommitSave(); var getRecipientList = await messageController.GetRecipientList(recipientList.RecipientListID); Assert.NotNull(getRecipientList); } }
public List <string> ValidateRecipientList(RecipientList list, RecipientList blocked) { List <string> invalidAddresses = new List <string>(); const int maxSize = 3900; // Run checks in batches, Mailgun does not like us // washing the lists like this. Max size to check is 8000 chars List <EmailAddress> batch = new List <EmailAddress>(); int size = 0; foreach (EmailAddress address in list.EmailAddresses) { // Check size (including separator) if ((size + address.Email.Length) > maxSize) { // Wash and clear the ones we've got so far invalidAddresses.AddRange(ValidateRecipientList(batch, blocked)); size = 0; batch.Clear(); } batch.Add(address); // Increase size used (including separator) size += address.Email.Length + 1; } // Finish up with the remaining invalidAddresses.AddRange(ValidateRecipientList(batch, blocked)); return(invalidAddresses); }
/// <summary> /// Add the EmailSource. /// </summary> private static void AddEmailSource(PXGraph graph, int?sourceEmailID, RecipientList recipients) { NotificationRecipient recipient = null; EMailAccount emailAccountRow = PXSelect <EMailAccount, Where < EMailAccount.emailAccountID, Equal <Required <EMailAccount.emailAccountID> > > > .Select(graph, sourceEmailID); if (emailAccountRow != null && emailAccountRow.Address != null) { recipient = new NotificationRecipient() { Active = true, Email = emailAccountRow.Address, Hidden = false, Format = "H" }; if (recipient != null) { recipients.Add(recipient); } } }
public async void TestBuildRecipientList() { var options = new DbContextOptionsBuilder <MessageContext>() .UseInMemoryDatabase(databaseName: "p3MessageService") .Options; using (var context = new MessageContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); Repo r = new Repo(context, new NullLogger <Repo>()); Mapper map = new Mapper(); Logic logic = new Logic(r, map, new NullLogger <Repo>()); var recipientList = new RecipientList { RecipientListID = Guid.NewGuid(), RecipientID = "56789" }; var buildRecipientList = await logic.BuildRecipientList(recipientList); Assert.NotNull(buildRecipientList); } }
public async void TestGetRecipientLists() { var options = new DbContextOptionsBuilder <MessageContext>() .UseInMemoryDatabase(databaseName: "p3MessageService") .Options; using (var context = new MessageContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); Repo r = new Repo(context, new NullLogger <Repo>()); var recipientList = new RecipientList { RecipientListID = Guid.NewGuid(), RecipientID = "3232344562" }; r.RecipientLists.Add(recipientList); await r.CommitSave(); var getRecipientLists = await r.GetRecipientLists(); Assert.NotNull(getRecipientLists); } }
protected static RecipientList GetPublicList() { RecipientList selectedList = null; RecipientLists lists = RecipientLists.ListOneType(RecipientListType.PublicList.ToString()); if (lists != null && lists.Items != null && lists.Items.Any()) { if (lists.Items.Count == 1) { selectedList = lists.Items.First(); } else { // We could have more than one, pick the one with name "Default" selectedList = lists.Items.Find(l => l.Name.ToLower().CompareTo("default") == 0); if (selectedList == null) { throw new ApplicationException( "There are more than one public lists, and none called \"Default\""); } } } else { throw new ApplicationException("There are no public recipient lists defined."); } return(selectedList); }
public async Task <IActionResult> Edit(RecipientList recipientList) { //int id, [Bind("Id")] RecipientList recipientList if (ModelState.IsValid) { try { _context.Update(recipientList); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RecipientListExists(recipientList.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(recipientList)); }
public SubscriptionResult UnsubscribeUsingBlocklist(string email, int listId) { if (string.IsNullOrEmpty(email)) { return(SubscriptionResult.EmailNotValid); } RecipientList selectedList = RecipientList.Load(listId); if (selectedList.ListType != RecipientListType.BlockList) { throw new ApplicationException("Specified list is not a block list"); } EmailAddress emailAddress = selectedList.CreateEmailAddress(email); emailAddress.Comment = "Unsubscribed using opt-out page."; emailAddress.Source = EmailAddressSource.SelfRegistered; emailAddress.Save(); // if already there, fine, no problem // if not there, we've added the email return(SubscriptionResult.Success); }
public SubscriptionResult Unsubscribe(string email, RecipientList recipientList) { if (string.IsNullOrEmpty(email)) { return(SubscriptionResult.EmailNotValid); } if (recipientList == null) { return(SubscriptionResult.RecipientListNotValid); } // Get a list to add to, will throw an exception if not found int count = recipientList.RemoveEmailAddresses(email); if (count == 0) { return(SubscriptionResult.NotMemberOfList); } else { return(SubscriptionResult.Success); } }
public void AddRecipientIfMissing(string emailAddress) { if (RecipientList.Contains(emailAddress)) { return; } RecipientList.Add(emailAddress); }
protected void lnkRemoveContents_Click(object sender, EventArgs e) { if (RecipientList != null) { RecipientList.DeleteEmailAddressItems(); // Rebind data BindJobData(RecipientList); } }
public void BindJobData(RecipientList list) { h2ListName.InnerText = list.Name; lblListDescription.Text = list.Description; lblCountOfEmails.Text = list.EmailAddressCount.ToString(); lnkEditItems.HRef = "RecipientItemsEdit.aspx?recipientlistid=" + this.RecipientList.Id.ToString(); //if (NewsletterJob.PageId > 0) // prPageToSend.PageLink = new EPiServer.Core.PageReference(job.PageId); }
public HttpResponseMessage Get(int id) { RecipientList list = RecipientList.Load(id); if (list == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } return(Request.CreateResponse(HttpStatusCode.OK, GetJsonResult <RecipientList>(list))); }
private static IEnumerable <string> GetRecipients() { if (File.Exists(Path.Combine(Directory.GetCurrentDirectory(), "Recipients.xml"))) { return(RecipientList.Get("errors")); } else { return(Config.Get("recipients").Split(',')); } }
public SubscriptionResult Unsubscribe(string email) { if (string.IsNullOrEmpty(email)) { return(SubscriptionResult.EmailNotValid); } RecipientList selectedList = GetPublicList(); return(Unsubscribe(email, selectedList)); }
public async Task <IActionResult> Create([Bind("Id")] RecipientList recipientList) { if (ModelState.IsValid) { _context.Add(recipientList); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(recipientList)); }
/// <summary> /// Remove a reicipent list from the job. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void cmdSelect_Click(object sender, CommandEventArgs e) { string recipListIdString = (string)e.CommandArgument; int recipListId = int.Parse(recipListIdString); RecipientList list = RecipientList.Load(recipListId); // Add the items int count = _job.FilterOnRecipients(recipListId); _jobUi.ShowInfo("Removed " + count.ToString() + " Recipients from Recipient List " + list.Name); }
private void cmdSubscribe_Click(object sender, System.EventArgs e) { string emailAddress = txtEmail.Text; if (emailAddress == null || emailAddress == string.Empty) { AddErrorMessage(Translate("/bvnetwork/sendmail/subscribe/errornoemail")); return; } emailAddress = emailAddress.Trim(); EPiMailEngine engine = new EPiMailEngine(); ArrayList resultArray = new ArrayList(); EmailAddresses importedItems = new EmailAddresses(); foreach (ListItem itm in this.chkNewsLetterLists.Items) { if (itm.Selected) { // Check that the user does not belong to the groups // already. RecipientList list = RecipientList.Load(Convert.ToInt32(itm.Value)); SubscriptionStatus status = new SubscriptionStatus(); status.RecipientListName = list.Name; //Load and check if the email typed by the user exists. EmailAddress emailItem = EmailAddress.Load(list.Id, emailAddress); if (emailItem == null) { // Create it, and save it. It is automatically // added to the WorkItems collection emailItem = list.CreateEmailAddress(emailAddress); // Save emailItem.Save(); status.SubscriptionResult = true; } else { // Already subscribes status.SubscriptionResult = true; status.Message = Translate("/bvnetwork/sendmail/subscribe/alreadysubscribe"); } resultArray.Add(status); } } // Done adding, now show the result rptResult.DataSource = resultArray; rptResult.DataBind(); }
public HttpResponseMessage AddRecipientsToListFromEPiServerGroupname(int id, string groupName) { RecipientList list = RecipientList.Load(id); if (list != null) { return(Request.CreateResponse(HttpStatusCode.OK, GetJsonResult <RecipientStatus>(AddEPiServerGroupRecipients(list, groupName)))); } return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "List not found")); }
// --------------------------- ConstructCommon ----------------------- private void ConstructCommon( ) { mToRecipients = new RecipientList( ); mCcRecipients = new RecipientList( ); mBccRecipients = new RecipientList( ); attachments = new ArrayList(); images = new ArrayList(); customHeaders = new ArrayList(); mixedBoundary = MailMessage.generateMixedMimeBoundary( ); altBoundary = MailMessage.generateAltMimeBoundary( ); relatedBoundary = MailMessage.generateRelatedMimeBoundary( ); }
public void ValidateMessage() { var recipientList = new RecipientList() { RecipientListID = Guid.NewGuid(), RecipientID = "1234567" }; var results = ValidateModel(recipientList); Assert.True(results.Count == 0); }
public HttpResponseMessage Delete(int id) { RecipientList list = RecipientList.Load(id); if (list == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } list.Delete(); return(Request.CreateResponse(HttpStatusCode.OK, "Recipient list deleted")); }
/// <summary> /// Create RecipientList entity with ListID from Message and RecipientID from input /// </summary> /// <param name="listId">RecipientListID</param> /// <param name="recId">RecipientID</param> /// <returns>RecipientList</returns> public async Task <RecipientList> BuildRecipientList(Guid listId, string recId) { RecipientList rL = new RecipientList() { RecipientListID = listId, RecipientID = recId }; await _repo.RecipientLists.AddAsync(rL); await _repo.CommitSave(); return(rL); }
public async Task <RecipientList> BuildRecipientList(RecipientList rLD) { RecipientList rL = new RecipientList() { RecipientListID = rLD.RecipientListID, RecipientID = rLD.RecipientID }; await _repo.RecipientLists.AddAsync(rL); await _repo.CommitSave(); return(rL); }
protected void cmdSearchFor_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtSearchFor.Text.Trim())) { return; } EmailAddresses items = RecipientList.Search(RecipientList.Id, "%" + txtSearchFor.Text + "%"); BindWorkItemData(items); //JobWorkItems items = JobWorkItems.Search(NewsletterJob.Id, "%" + txtSearchFor.Text + "%"); //BindWorkItemData(items); }
/// <summary> /// Add the Employee(s) info as a recipient(s) in the Email template generated by Appointment. /// </summary> private static void AddEmployeeStaffRecipient(AppointmentEntry graphAppointmentEntry, int?bAccountID, string type, NotificationRecipient recSetup, RecipientList recipients) { NotificationRecipient recipient = null; Contact contactRow = null; if (type == BAccountType.EmployeeType) { contactRow = PXSelectJoin <Contact, InnerJoin <BAccount, On < BAccount.parentBAccountID, Equal <Contact.bAccountID>, And <BAccount.defContactID, Equal <Contact.contactID> > > >, Where < BAccount.bAccountID, Equal <Required <BAccount.bAccountID> >, And < BAccount.type, Equal <Required <BAccount.type> > > > > .Select(graphAppointmentEntry, bAccountID, type); } else if (type == BAccountType.VendorType) { contactRow = PXSelectJoin <Contact, InnerJoin <BAccount, On < Contact.contactID, Equal <BAccount.defContactID> > >, Where < BAccount.bAccountID, Equal <Required <BAccount.bAccountID> >, And < BAccount.type, Equal <Required <BAccount.type> > > > > .Select(graphAppointmentEntry, bAccountID, type); } if (contactRow != null && contactRow.EMail != null) { recipient = new NotificationRecipient() { Active = true, Email = contactRow.EMail, Hidden = recSetup.Hidden, Format = recSetup.Format }; if (recipient != null) { recipients.Add(recipient); } } }
/// <summary> /// Adds an email address to the one public recipient list, or the one named /// "Default" if there are more than one. /// </summary> /// <remarks> /// We do not care if the address already exists, due to /// security conserns, we won't tell if it do exists, just add it /// </remarks> /// <param name="email">The email address to add. It will be validated.</param> /// <returns>A success or fail message.</returns> public SubscriptionResult Subscribe(string email) { if (string.IsNullOrEmpty(email)) { return(SubscriptionResult.EmailNotValid); } // throw new ArgumentNullException("email", "Email address cannot be empty."); // Note! This may throw an error, and we want to, as it needs to // be handled by the application RecipientList selectedList = GetPublicList(); return(AddSubscriptionToList(email, selectedList)); }
private void cmdUnsubscribe_Click(object sender, System.EventArgs e) { string emailAddress = txtEmail.Text; if (emailAddress == null || emailAddress == string.Empty) { AddErrorMessage(Translate("/bvnetwork/sendmail/unsubscribe/errornoemail")); return; } emailAddress = emailAddress.Trim(); EPiMailEngine engine = new EPiMailEngine(); ArrayList resultArray = new ArrayList(); EmailAddresses importedItems = new EmailAddresses(); foreach (ListItem itm in this.chkNewsLetterLists.Items) { if (itm.Selected) { //Load the selected recipient list RecipientList list = RecipientList.Load(Convert.ToInt32(itm.Value)); SubscriptionStatus status = new SubscriptionStatus(); status.RecipientListName = list.Name; //load user email address EmailAddress emailItem = EmailAddress.Load(list.Id, emailAddress); if (emailItem != null) { //Delete the user from the list, and show a confirm message emailItem.Delete(); status.SubscriptionResult = true; status.Message = Translate("/bvnetwork/sendmail/unsubscribe/recipientremoved"); } else { status.SubscriptionResult = false; status.Message = Translate("/bvnetwork/sendmail/unsubscribe/nosubscriptionfound"); } //add the result to the array list. resultArray.Add(status); } } // Done adding, now show the result rptResult.DataSource = resultArray; rptResult.DataBind(); }