<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def handle_alarm(sender, **kwargs):
 """ Handles alarm events from the AlarmDecoder. """

    zone = kwargs.pop('zone', None)
    text = "Alarm: Zone {0}".format(zone)

    # Build the email message
    msg = MIMEText(text)
    msg['Subject'] = SUBJECT
    msg['From'] = FROM_ADDRESS
    msg['To'] = TO_ADDRESS

    s = smtplib.SMTP(SMTP_SERVER)

    # Authenticate if needed
    if SMTP_USERNAME is not None:
        s.login(SMTP_USERNAME, SMTP_PASSWORD)

    # Send the email
    s.sendmail(FROM_ADDRESS, TO_ADDRESS, msg.as_string())
    s.quit()

    print('sent alarm email:', text)