コード例 #1
0
        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");
        }
コード例 #2
0
        /// <summary>
        /// Loads the specified list.
        /// </summary>
        /// <param name="name">The name of the list</param>
        /// <returns>The list if found, null if no job with the name could be found</returns>
        public static RecipientList Load(string name)
        {
            RecipientLists allLists = RecipientLists.ListAll();
            RecipientList  list     = allLists.FirstOrDefault(l => l.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase));

            return(list);
        }
コード例 #3
0
ファイル: ListEdit.aspx.cs プロジェクト: tsolbjor/Newsletter
        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);
        }
コード例 #4
0
        /// <summary>
        /// Loads the specified list.
        /// </summary>
        /// <param name="recipientListId">The id of the recipient list.</param>
        /// <returns>The job if found, null if no job with the id could be found</returns>
        public static RecipientList Load(int recipientListId)
        {
            RecipientData dataUtil   = GetWorker();
            DataTable     recipTable = dataUtil.RecipientListGetById(recipientListId);

            // See if we found one
            if (recipTable.Rows.Count != 1)
            {
                return(null);
            }

            // Found one
            RecipientList recipList = new RecipientList(recipTable.Rows[0]);

            return(recipList);
        }
コード例 #5
0
        /// <summary>
        /// Saves the job
        /// </summary>
        public virtual void Save()
        {
            // verify paramterers before sending them to the database
            if (string.IsNullOrEmpty(Name))
            {
                throw new ArgumentException("Name cannot be null or empty");
            }

            if (Name.Length > 255)
            {
                throw new ArgumentException("Name cannot be more then 255 characters");
            }

            if (string.IsNullOrEmpty(Description) == false)
            {
                if (Description.Length > 2000)
                {
                    throw new ArgumentException("Description cannot be more then 2000 characters");
                }
            }

            RecipientData dataUtil = GetWorker();

            if (Id == 0)
            {
                // New list
                // Verify that we do not have a list with same name
                RecipientList existing = Load(_name);
                if (existing != null)
                {
                    throw new ArgumentException("A recipient list with the same name already exists.");
                }

                int newId = dataUtil.RecipientListCreate(_type, _name, _description);
                _id = newId;
            }
            else
            {
                // Edit existing
                dataUtil.RecipientListEdit(_id, _type, _name, _description);
            }
        }
コード例 #6
0
        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;
            }
        }
コード例 #7
0
        protected SubscriptionResult AddSubscriptionToList(string email, RecipientList selectedList)
        {
            EmailSyntaxValidator validator = new EmailSyntaxValidator(email, false);
            if (validator.IsValid)
            {
                _log.Debug("Attemt to add email subscription for {0}", email);

                EmailAddress emailAddress = selectedList.CreateEmailAddress(email);
                emailAddress.Source = EmailAddressSource.SelfRegistered;
                emailAddress.Added = DateTime.Now;
                emailAddress.Save(); // Will add it to the list, or update it if it exists

                return SubscriptionResult.Success;
            }
            else
            {
                _log.Warning("Failed to add email subscription for '{0}' (not valid)", email);
                return SubscriptionResult.EmailNotValid;
            }
        }
コード例 #8
0
ファイル: RecipientList.cs プロジェクト: tsolbjor/Newsletter
        /// <summary>
        /// Loads the specified list.
        /// </summary>
        /// <param name="recipientListId">The id of the recipient list.</param>
        /// <returns>The job if found, null if no job with the id could be found</returns>
        public static RecipientList Load(int recipientListId)
        {
            RecipientData dataUtil = GetWorker();
            DataTable recipTable = dataUtil.RecipientListGetById(recipientListId);

            // See if we found one
            if (recipTable.Rows.Count != 1)
            {
                return null;
            }

            // Found one
            RecipientList recipList = new RecipientList(recipTable.Rows[0]);
            return recipList;
        }
コード例 #9
0
        public List<string> ValidateRecipientList(List<EmailAddress> recipientAddresses, RecipientList blocked)
        {
            _log.Debug("Validating {0} emails using block list {1} ({2})", recipientAddresses.Count, blocked.Name, blocked.Id);

            if(recipientAddresses.Count == 0)
                return new List<string>();

            MailgunSettings settings = GetSettings();
            RestClient client = new RestClient();
            client.BaseUrl = new Uri("https://api.mailgun.net/v2");
            client.Authenticator = new HttpBasicAuthenticator("api", settings.PublicKey);

            if (string.IsNullOrEmpty(settings.ProxyAddress) == false)
            {
                client.Proxy = new WebProxy(settings.ProxyAddress, settings.ProxyPort); // Makes it easy to debug as Fiddler will show us the requests
            }

            RestRequest request = new RestRequest();

            // We're sending a lot of data, which should
            // be a post, but Mailgun does not allow that
            // request.Method = Method.POST;

            request.Resource = "/address/parse";

            // Validate strict
            request.AddParameter("syntax_only", false);

            string addresses = "";

            foreach (EmailAddress emailAddress in recipientAddresses)
            {
                addresses += emailAddress.Email + ",";
            }

            _log.Debug("Length of address field sent to Mailgun: {0}", addresses.Length);

            if(addresses.Length > 8000)
            {
                throw new ApplicationException("Mailgun only accepts address fields with length of 8000 characters.");
            }

            request.AddParameter("addresses", addresses.TrimEnd(','));

            var response = client.Execute(request);
            _log.Debug("Mailgun responded with status: {0} - {1}", (int)response.StatusCode, response.StatusDescription);
            if (response.StatusCode == HttpStatusCode.OK)
            {
                /*
                {
                    "parsed": [
                        "Alice <*****@*****.**>",
                        "*****@*****.**"
                    ],
                    "unparseable": [
                        "example.com"
                    ]
                }
                */
                Dictionary<string, List<string>> resultParams = null;
                try
                {
                    resultParams = new JsonDeserializer().Deserialize<Dictionary<string, List<string>>>(response);
                }
                catch (Exception e)
                {
                    _log.Warning("Unable to parse Mailgun response.", e);
                }

                // Update all recipients with information
                if (resultParams != null)
                {
                    List<string> invalidAddresses = resultParams["unparseable"];
                    foreach (string address in invalidAddresses)
                    {
                        EmailAddress emailAddress = recipientAddresses.Find(a => a.Email.Equals(address, StringComparison.InvariantCultureIgnoreCase));
                        if (emailAddress != null)
                        {
                            emailAddress.Comment = "Mailgun reported address as invalid.";
                            emailAddress.Save();
                        }

                        EmailAddress blockedAddress = blocked.CreateEmailAddress(address);
                        blockedAddress.Comment = "Mailgun reported address as invalid.";
                        blockedAddress.Save();
                    }

                    return invalidAddresses;
                }
            }
            else
            {
                // Attempt to log error from Mailgun
                if(string.IsNullOrEmpty(response.ErrorMessage) == false)
                    _log.Warning(response.ErrorMessage);

                if(string.IsNullOrEmpty(response.Content) == false)
                    _log.Debug(response.Content);

                throw new ApplicationException("Cannot validate email addresses using Mailgun: " + response.ErrorMessage);
            }
            return null;
        }
コード例 #10
0
        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;
        }