Rock.Communication.Email.ProcessBounce C# (CSharp) Method

ProcessBounce() public static method

Processes the bounce.
public static ProcessBounce ( string email, BounceType bounceType, string message, System.DateTime bouncedDateTime ) : void
email string The email.
bounceType BounceType Type of the bounce.
message string The message.
bouncedDateTime System.DateTime The bounced date time.
return void
        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();
            }
        }