AnsweredAssumed Answered

How to remove email addresses through an after save logic hook?

Question asked by Lee Gaska on May 6, 2016
Latest reply on May 9, 2016 by Lee Gaska

Hello, All.

 

I would like to scrub bogus email addresses (that are entered during testing, etc) through an after save logic hook. I am able to mark an email address as invalid using the code below. However, I would like to completely remove the email address (or update it as empty), so the user is prompted to enter this information next time the record is modified. Any ideas on how to correctly do this?


Thank you!

 

foreach ($bean->emailAddress->addresses as $k=>$emailaddress ) {

            if( $ema = $emailaddress['email_address'] ) {

                if(

                    stripos($ema,'@none.com') !== FALSE ||

                    stripos($ema,'@test.com') !== FALSE ||

                    stripos($ema,'@nunya.com') !== FALSE ||

                    stripos($ema,'@testing.com') !== FALSE

                ) {

 

                    $sea = new SugarEmailAddress();

                    $sea = $bean->emailAddress;

                    $sea->addAddress($ema, true, null, true);

                   

                    $sea->save($bean->id,$bean->module_dir);

                   

                }

            }

        }

Outcomes