Trigger an automation when an email is recieved

I would say it’s a one-time automation for this device (project) So far I have, which doesn’t seem to work, I can see the Trigger being triggered but the socket is not turning on.

alias: New automation
description: ""
trigger:
  - platform: state
    entity_id: sensor.imap_device
  - platform: event
    event_type: imap_content
    id: custom_event
    event_data:
      sender: [email protected]
      initial: true
condition:
  - condition: state
    entity_id: sensor.imap_device
    state: |-
      {% if 'Project Created' in trigger.event.data["subject"] %}
         turn_on
      {% endif %}
action:
  - type: turn_on
    device_id: 0d1855262bdd676fe0c801bf47efce92
    entity_id: ac2026550abdf08c3be574edc5249237
    domain: switch
  - delay:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
  - type: turn_off
    device_id: 0d1855262bdd676fe0c801bf47efce92
    entity_id: ac2026550abdf08c3be574edc5249237
    domain: switch
mode: single