Add image to mail notification not working

Hi all,

I have the problem to add an image to a mail notification

This is the YAML. I send a mail to my Gmail account on an IOS device. The mail is received, but without attachment. I checked, and the file is saved in the correct location. What I’m doing wrong?

alias: Nieuwe automatisering
description: “”
trigger:

  • platform: state
    entity_id:
    • binary_sensor.ip_camera_field_detection
      from: null
      to: “on”
      condition:
      action:
  • service: camera.snapshot
    data:
    filename: /config/www/tmp/voordeur.jpg
    enabled: true
    target:
    entity_id: camera.192_168_0_12
  • delay:
    hours: 0
    minutes: 0
    seconds: 2
    milliseconds: 0
    enabled: true
  • service: notify.xxxxxx_gmail_com
    metadata: {}
    data:
    message: test
    title: test
    target: [email protected]
    data:
    image: /config/local/tmp/voordeur.jpg
    mode: single

try this:

alias: camera detectie
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.ip_camera_field_detection
    from: null
    to: 'on'
condition: []
action:
  - service: camera.snapshot
    data:
      entity_id: camera.192_168_0_12
      filename: 
        /media/snapshots/voordeur_{{ now ().year }}_{{ now ().month }}_{{ now
        ().day }}_{{ now ().hour }}_{{ now ().minute }}.jpg
  - service: notify.xxxxxx_gmail_com
    data:
      title: camera detectie
      message: camera detectie om {{now().strftime("%H:%M")}}
      target: [email protected]
      data:
        image: 
          /media/local/snapshots/voordeur_{{ now ().year }}_{{ now ().month
          }}_{{ now ().day }}_{{ now ().hour }}_{{ now ().minute }}.jpg
mode: single

Thanks for your quick respons.

I tried your solution. The JPG is created and the mail is sended. But still without the image.

You asked the same question in another topic. Did you follow the instructions in that topic’s Solution post? Specifically the instructions for adding the directory, containing your file, to allowlist_external_dirs in the homeassistant section of your configuration.yaml file?

For example:

homeassistant:
  allowlist_external_dirs:
    - '/config/www/tmp'

Yes, I configured their solution. This is the automation YAML en configuration YAML

alias: camera detectie
description: “”
trigger:

  • platform: state
    entity_id:
    • binary_sensor.ip_camera_field_detection
      from: null
      to: “on”
      condition:
      action:
  • service: camera.snapshot
    data:
    entity_id: camera.192_168_0_12
    filename: /config/www/tmp/voordeur.jpg
  • delay:
    hours: 0
    minutes: 0
    seconds: 5
    milliseconds: 0
  • service: notify.xxxxx_gmail_com
    metadata: {}
    data:
    message: Test
    title: Test
    target: [email protected]
    data:
    images: /config/www/tmp/voordeur.jpg
    mode: single

Loads default set of integrations. Do not remove.

default_config:

Load frontend themes from the themes folder

frontend:
themes: !include_dir_merge_named themes

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

binary_sensor:

  • platform: hikvision
    host: 192.168.0.12
    username:
    password:

homeassistant:
allowlist_external_dirs:
- /config/www/tmp

Hard
to
tell
if
what
you
have
posted
is
free
of
syntax
errors
because
it
is
unformatted

  • Y
    A
    M
    L

. :wink:

See guideline FAQ guideline 11: Format it properly

Sorry, hereby the correct format

Configuration.yaml

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

binary_sensor:
  - platform: hikvision
    host: 192.168.0.12
    username:
    password: 

homeassistant:
  allowlist_external_dirs:
    - /config/www/tmp

Automation.yaml

alias: camera detectie
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.ip_camera_field_detection
    from: null
    to: "on"
condition: []
action:
  - service: camera.snapshot
    data:
      entity_id: camera.192_168_0_12
      filename: /config/www/tmp/voordeur.jpg
  - delay:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
  - service: notify.xxxx_gmail_com
    metadata: {}
    data:
      message: Test
      title: Test
      target: [email protected]
      data:
        images: /config/www/tmp/voordeur.jpg
mode: single

This works for me.

alias: camera detectie
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.ip_camera_field_detection
    from: null
    to: "on"
condition: []
action:
  - service: camera.snapshot
    data:
      entity_id: camera.192_168_0_12
      filename: www/tmp/voordeur.jpg
  - delay:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
  - service: notify.xxxx_gmail_com
    metadata: {}
    data:
      message: “Test”
      title: Test
      target: [email protected]
      data:
        images: 
          - www/tmp/voordeur.jpg
        html: |
          <img src="cid:voordeur.jpg">
mode: single

I don’t have the metadata or target tags in my notify call, but if this works for you in other automations it should be fine here.

Thanks! I tried your solution, but does not work for me.