Attaching images to email notifications

I am trying to send images from my security camera using email and I can’t get them to attach. Emails without attachments are working, so the issue is not the gmail notifier.
If I do the same basic thing but send the image via ios notification the images work.
Can anyone see something I am missing?

data_template:
  data:
    images: 'file:///192.168.0.104/snap.jpeg'
  message: 'Front Porch {{ now().strftime(''%H:%M:%S'')}}'
  title: Motion Detected
service: notify.gmail_notifier

For reference when I attach an image in the ios notification it works by using:
url: 'http://192.168.0.104/snap.jpeg'

For the email I have tried using:
images: 'file:///192.168.0.104/snap.jpeg'
images: 'http://192.168.0.104/snap.jpeg'
images: '192.168.0.104/snap.jpeg'
But without success.

An example error from my log:

2020-08-09 07:45:48 WARNING (SyncWorker_1) [homeassistant.components.smtp.notify] Attachment i not found. Skipping
2020-08-09 07:45:48 WARNING (SyncWorker_1) [homeassistant.components.smtp.notify] Attachment l not found. Skipping
2020-08-09 07:45:48 WARNING (SyncWorker_1) [homeassistant.components.smtp.notify] Attachment e not found. Skipping
2020-08-09 07:45:48 WARNING (SyncWorker_1) [homeassistant.components.smtp.notify] Attachment : not found. Skipping

So it’s trying to attach each character as an image? (see that its starting to spell "FILE)?

I tried using “image” as opposed to “images” in he syntax - which results in the email going through but no attachment as I suspect its simply ignoring that unknown syntax.

Any suggestions?

Try

data:
  html: >
    <img src="http://192.168.0.104/snap.jpeg">

It won’t work though if you aren’t connected to local wifi, you should probably download the image yourself in host it in /local/ or get the entity_picture.

2 Likes

Assuming you are using the SMTP integration.

Try adding the images as a list as per the example in the docs. Try with or without quotes around the filename.

data_template:
  data:
    images: 
      - 'file:///192.168.0.104/snap.jpeg'
  message: 'Front Porch {{ now().strftime(''%H:%M:%S'')}}'
  title: Motion Detected
service: notify.gmail_notifier

Yes I am using the SMTP integration. I tried the above and it results in:

[homeassistant.components.smtp.notify] Attachment file:///192.168.0.104/snap.jpeg not found. Skipping```

I tried this with 3x slashes, 2x slashes, quotes and no quotes. Same result.

This is the closest I have got (thanks!). I can see an image was attached, but it’s broken.
I would have thought as I am on my local network when sending the image it would work and when testing I am also on the same network. As well as the fact that the ios notification works.

Do you have any links/info for me to investigate downloading the image myself? and/or using the entity_picture?
This is my first week using HomeAssistant, so I am definitely still a noob, but am progressing :slight_smile:

Ah, ok, I see the camera.snapshot service … that looks promising. (thanks for the idea @KTibow ).

I finally got it working. Writing it here in case other people have the same issue.

data:
  entity_id: camera.front
  filename: /config/tmp/snapshot.jpeg
service: camera.snapshot
data_template:
  data:
    images:
      - '/config/tmp/snapshot.jpeg'
  message: 'Front Porch {{ now().strftime(''%H:%M:%S'')}}'
  title: Motion Detected
service: notify.gmail_notifier

Also, I had to add this to my config:

homeassistant:
  allowlist_external_dirs:
    - '/config/tmp'

Thanks to @KTibow and @metbril for their assistance.

2 Likes

Hi

My SMTP notification works when sending only text.
This works:
{
“title”: “Beweging voordeur”,
“message”: “Beweging voordeur”
}

But now I want to attach an image. I tried several examples.
What am I doing wrong?
What should I add tothe JSON editor to send for example this image:
/config/tmp/snapshot_camera_voordeur.jpg

Everything you need has been previously stated. You add

data:
  images:
    - "/config/tmp/snapshot_camera_voordeur.jpg"

to your service call.

Sorry, I’m too new and still a dummy zero.

I tried already to add this in my Node-red automation. But it is giving an error.
As you can see in the image, the Service cannot be called anymore
Notify SMTP

By adding these lines I receive a “YAML parsing error”
{
“title”: “Beweging voordeur”,
“message”: “Beweging voordeur”,
“data”:
“images”:
- “/config/tmp/snapshot_camera_voordeur.jpg”
}

You should use YAML, not JSON. It’s standard in Home Assistant.

Sorry, I don’t understand this.
My screenshot (see higher) shows Service Data (YAML, optional)

My Nodered shows only JSON as a possibility.
Nodered

My Nodered service call is working with these lines
JSON

Well then turn

data:
  images:
    - "/config/tmp/snapshot_camera_voordeur.jpg"

into

"data": {
  "images": ["/config/tmp/snapshot_camera_voordeur.jpg"]
}
1 Like

Thank you very much. It’s working now.
I have still to learn a lot

Hi
You have helped me in the past by giving the correct syntax for sending an image in an email notification.

Now I’m trying to send the contents of a payload. The payload is a concatenation of several measured values that I prepared in a function.

image

And the function is giving me a correct output
image

But the next syntax gives always a call-service error: expected dict for dictionary value @ data[‘data’]"

{
“title”: “Temperaturen”,
“message”: “Temperaturen”,
“data”: [
“msg.payload”
]
}

The data field is supposed to be a dictionary, a structure where there are keys and values denoted by { and }.

just popping in to say thank you!! This was exactly the post I was looking for!! Legends the lot of you! :slight_smile:

Hi all,

I have the same problem and it still not works for me with all the solutions tried.

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/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:
    images:
    - /config/local/voordeur.jpg
    mode: single