Send email on Feature Code

I am trying to get my freepbx to send an email when the system is switched from day to night mode. I believe I have a working feature code that does that(*271 anyway I can chance that?). I would like the email sent when the time condition changes. How would I go about doing that ?