How to attach image entity to an email

Hi,
I have an image entity (image.doorbell_event_image) that shows up nice in HA.
How can I attach that into an email notification?

This works fine:

  - service: notify.email_user
    data:
      title: Doorbell
      message: Doorbell

But if I add what I think would be correct, I don’t even receive an email:

  - service: notify.email_user
    data:
      title: Doorbell
      message: Doorbell
      image: /api/image_proxy/image.doorbell_event_image

Ideas anyone?

Thanks

This is discussed here https://community.home-assistant.io/t/attaching-images-to-email-notifications/217291
See post that is marked as the solution.

Thanks for the quick answer, but there the discussion is how to attach a jpeg image.
In my case I want to attach the picture from the entity “image.doorbell_event_image”
I do not know where its image is stored or how it is named.

I don’t think that this is possible.

Anyone with more info, I cannot be the first wanting to send a image entity attached to an email?

1 Like

I have just tested this to notify notifications on my Android.

for my device, there is an access token required, which can be found in the image entities attributes.

service: notify.notify
data:
  message: Door PIR
  data:
    image: >-
      /api/image_proxy/image.dp2_door_camera_last_motion_image?token=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Thanks for your answer, I think it is not the same for an email, can you describe where to find the atributes if there is any in my image entity, could find anything under settings?

Just to be sure: did you already try this (following SMTP Usage):

- service: notify.email_user
    data:
      title: Doorbell
      message: Doorbell
      data:
          images:
              - /api/image_proxy/image.doorbell_event_image

If this does not work either, then do you have access to the doorbell camera stream?
If so, you can try this:

  - service: camera.snapshot
    data:
      filename: /snapshots/doorbell.jpg
    target:
      entity_id: camera.doorbell
  - service: notify.email_user
    data:
      title: Doorbell
      message: Doorbell
      data:
          images:
              - /snapshots/doorbell.jpg

Like this you first take a snapshot and store it in a local folder, and then send that snapshot via e-mail.
In this case the /snapshots/ folder should exist in the root, next to the /config/ folder.

Note that you have to ensure access to this local folder: depending on where the local folder is you might need to add this to configuration.yaml:

homeassistant:
  allowlist_external_dirs:
    - '<path-to>/snapshots'

Thanks Ed,

From the firs code snip i get a bit further, but not an actual image attached:
image

For the second snip, this Doorbell does not start an live stream at the same moment as it is ringing, but this could maybe be accieved, have to think about it.

Hi Ed,
The second snip worked for me Thanks a lot!
I start the stream first, take the snapshot, turn off the stream and then attach the snapshot in an email.
There is quite a long delay (counted about 7 seconds from trigger to snapshot), but its the best for now.

Great!
One more idea (although a wild guess). You wrote:

What do you see when you right_click on this received image in the HA UI and select something like “Save image as…”?
Is this proposed image file name always the same?
If so, assuming that the image file name always is filename.jpg, you could try this:

  - service: notify.email_user
    data:
      title: Doorbell
      message: Doorbell
      data:
          images:
              - /api/image_proxy/image.doorbell_event_image/filename.jpg

Thanks Ed for thinking this further, so much appreciated!
I sadly only get:

image

The Doorbell can detect person and also pressing the ring button (on the snip 2 idea).
Made 2 different automations on this, seems like during this 7 second delay from detecting person and pressing ring that later automation gets discarded

Ah! I just realized that image.doorbell_event_image (being an entity) probably cannot directly be inserted in a full file path because this is a string.
But I re-read the post from ahaghshenas, and this still might be the solution.
You did not try his solution yet, did you?
If you go to Developer tools → States and enter the entity image.doorbell_event_image in the search field it shows the access_token and entity_picture attributes.
Following the solution from @ahaghshenas it looks like this entity_picture attribute is what you have to enter in the code like this:

- service: notify.email_user
    data:
      title: Doorbell
      message: Doorbell
      data:
          images:
              - /api/image_proxy/image.doorbell_event_image?token=xxxxxxxxxxx

But if this works I am still not sure that this access token is static: it might be changed with every new snapshot. So in that case it will not work consistently. But it’s worth a try.

Hi Ed,

The token seems to be static, but I did not get the picture inte a mail this way.

OK, then I am out of ideas.
If no one else has any suggestions then it might be good to ask the code owners to look into this issue, because this lacking method of adding images via an image entity to e-mails might be a bug or missing feature in the SMTP Notification integration.
This should not be that hard to add because the same thing seems to be already supported by for instance the Companion App Notifications.
You could post an Issue on GitHub.

Im working on the same thing now where you able to find a solution ?

I seem to be missing proper path for the /api/image_proxy for the automation, but Im able to see the URL in the browser… What is the correct path to put in for the /api/image_proxy/ inside automation for SMTP or IOS notifications ? Does anyone know ?

Hi @stev3,
Sadly did not solve this and gave up :frowning:
Hope you can come further on this!

That sucks, Im sure there is a way to do this since image is viewable in browser using the URL, but Im not sure where or how HA exposes it internally…

My workaround on this was to start the P2P stream and take a snapshot and then stop the stream and mail the snapshot.
This sadly stopped working after upgrade to HA 2023-10-XX