예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
        /// <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);
        }
예제 #4
0
        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)));
        }
예제 #5
0
        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"));
        }
예제 #6
0
        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();
        }
예제 #7
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"));
        }
예제 #8
0
        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();
        }
예제 #9
0
        public SubscriptionResult Unsubscribe(string email, int recipientList)
        {
            if (string.IsNullOrEmpty(email))
            {
                return(SubscriptionResult.EmailNotValid);
            }

            if (recipientList == 0)
            {
                return(SubscriptionResult.RecipientListNotValid);
            }

            // Get a list to add to, will throw an exception if not found
            RecipientList selectedList = RecipientList.Load(recipientList);

            return(Unsubscribe(email, selectedList));
        }
예제 #10
0
        public HttpResponseMessage AddRecipientsToListFromList(int sourceListId, int destinationListId)
        {
            RecipientList destList   = RecipientList.Load(destinationListId);
            RecipientList sourceList = RecipientList.Load(sourceListId);

            if (destList != null && sourceList != null)
            {
                int             addedAddresses = destList.AddRecipientItemsFromRecipientList(sourceList.Id);
                RecipientStatus status         = new RecipientStatus {
                    ImportedEmails = addedAddresses
                };

                return(Request.CreateResponse(HttpStatusCode.OK,
                                              GetJsonResult <RecipientStatus>(status)));
            }

            return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Source or Destination list not found"));
        }
예제 #11
0
        /// <summary>
        /// Adds an email address to the specificed recipient list
        /// </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>
        /// <param name="recipientList">The ID of the recipient list</param>
        /// <returns>A success or fail message.</returns>
        public SubscriptionResult Subscribe(string email, int recipientList)
        {
            if (string.IsNullOrEmpty(email))
            {
                return(SubscriptionResult.EmailNotValid); // throw new ArgumentNullException("email", "Email address cannot be empty.");
            }
            if (recipientList == 0)
            {
                return(SubscriptionResult.RecipientListNotValid); // throw new ArgumentException("recpientList cannot be 0", "recipientList");
            }
            // Get a list to add to, will throw an exception if not found
            RecipientList selectedList = RecipientList.Load(recipientList);

            if (selectedList == null)
            {
                return(SubscriptionResult.RecipientListNotValid);
                // throw new ApplicationException("No list with id " + recipientList + " exists.");
            }

            return(AddSubscriptionToList(email, selectedList));
        }
예제 #12
0
        public HttpResponseMessage AddRecipientsToJobFromList(int sourceListId, int jobId)
        {
            Job job = Job.Load(jobId);

            if (job == null)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Job not found"));
            }
            RecipientList sourceList = RecipientList.Load(sourceListId);

            if (sourceList == null)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Source list not found"));
            }

            int             addedAddresses = job.AddWorkItemsFromRecipientList(sourceList.Id);
            RecipientStatus status         = new RecipientStatus {
                ImportedEmails = addedAddresses
            };

            return(Request.CreateResponse(HttpStatusCode.OK, GetJsonResult <RecipientStatus>(status)));
        }