Esempio n. 1
0
        /// <summary>
        /// Processes the bounce.
        /// </summary>
        /// <param name="email">The email.</param>
        /// <param name="bounceType">Type of the bounce.</param>
        /// <param name="message">The message.</param>
        /// <param name="bouncedDateTime">The bounced date time.</param>
        public static void ProcessBounce(string email, BounceType bounceType, string message, DateTime bouncedDateTime)
        {
            // currently only processing hard bounces
            if (bounceType != BounceType.HardBounce)
            {
                return;
            }

            string bounceMessage = message.IsNotNullOrWhiteSpace() ? $" ({message})" : "";

            // get people who have those emails
            PersonService personService   = new PersonService(new RockContext());
            var           peopleWithEmail = personService.GetByEmail(email).Select(p => p.Id).ToList();

            foreach (int personId in peopleWithEmail)
            {
                RockContext rockContext = new RockContext();
                personService = new PersonService(rockContext);
                Person person = personService.Get(personId);

                if (person.IsEmailActive == true)
                {
                    person.IsEmailActive = false;
                }

                person.EmailNote = $"Email experienced a {bounceType.Humanize()} on {bouncedDateTime.ToShortDateString()}{bounceMessage}.";
                rockContext.SaveChanges();
            }
        }
Esempio n. 2
0
        private static string GetEmailNote(BounceType bounceType, string message, DateTime bouncedDateTime)
        {
            var messages = new Dictionary <string, string>
            {
                { "550", "The user's mailbox was unavailable or could not be found." },
                { "551", "The intended mailbox does not exist on this recipient server." },
                { "552", "This message is larger than the current system limit or the recipient's mailbox is full." },
                { "553", "The message was refused because the mailbox name is either malformed or does not exist." },
                { "554", "Email refused." },
            };

            var emailNote = message;

            foreach (string key in messages.Keys)
            {
                if (message.StartsWith(key))
                {
                    emailNote = messages[key];
                    break;
                }
            }

            emailNote = $"Email experienced a {bounceType.Humanize()} on {bouncedDateTime.ToShortDateString()}. {emailNote}";
            return(emailNote.SubstringSafe(0, 250));
        }
Esempio n. 3
0
        /// <summary>
        /// Processes the bounce.
        /// </summary>
        /// <param name="email">The email.</param>
        /// <param name="bounceType">Type of the bounce.</param>
        /// <param name="message">The message.</param>
        /// <param name="bouncedDateTime">The bounced date time.</param>
        public static void ProcessBounce(string email, BounceType bounceType, string message, DateTime bouncedDateTime)
        {
            // currently only processing hard bounces
            if (bounceType == BounceType.HardBounce)
            {
                string bounceMessage = message.IsNotNullOrWhitespace() ? $" ({message})" : "";

                // get people who have those emails
                RockContext   rockContext   = new RockContext();
                PersonService personService = new PersonService(rockContext);

                var peopleWithEmail = personService.GetByEmail(email);

                foreach (var person in peopleWithEmail)
                {
                    person.IsEmailActive = false;
                    person.EmailNote     = $"Email experienced a {bounceType.Humanize()} on {bouncedDateTime.ToShortDateString()}{bounceMessage}.";
                }

                rockContext.SaveChanges();
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Processes the bounce.
        /// </summary>
        /// <param name="email">The email.</param>
        /// <param name="bounceType">Type of the bounce.</param>
        /// <param name="message">The message.</param>
        /// <param name="bouncedDateTime">The bounced date time.</param>
        public static void ProcessBounce( string email, BounceType bounceType, string message, DateTime bouncedDateTime )
        {
            // currently only processing hard bounces
            if ( bounceType == BounceType.HardBounce )
            {
                // get people who have those emails

                RockContext rockContext = new RockContext();
                PersonService personService = new PersonService( rockContext );

                var peopleWithEmail = personService.GetByEmail( email );

                foreach ( var person in peopleWithEmail )
                {
                    person.IsEmailActive = false;

                    person.EmailNote = String.Format( "Email experienced a {0} on {1} ({2}).", bounceType.Humanize(), bouncedDateTime.ToShortDateString(), message );
                }

                rockContext.SaveChanges();
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Processes the bounce.
        /// </summary>
        /// <param name="email">The email.</param>
        /// <param name="bounceType">Type of the bounce.</param>
        /// <param name="message">The message.</param>
        /// <param name="bouncedDateTime">The bounced date time.</param>
        public static void ProcessBounce(string email, BounceType bounceType, string message, DateTime bouncedDateTime)
        {
            // currently only processing hard bounces
            if (bounceType == BounceType.HardBounce)
            {
                // get people who have those emails

                RockContext   rockContext   = new RockContext();
                PersonService personService = new PersonService(rockContext);

                var peopleWithEmail = personService.GetByEmail(email);

                foreach (var person in peopleWithEmail)
                {
                    person.IsEmailActive = false;

                    person.EmailNote = String.Format("Email experienced a {0} on {1} ({2}).", bounceType.Humanize(), bouncedDateTime.ToShortDateString(), message);
                }

                rockContext.SaveChanges();
            }
        }