Camera Snapshot : Notify gmail with attachment

Hello,

I have this automation which works fine :slight_smile:

automation:

  - alias: Camera - Test
    trigger:
    - entity_id: binary_sensor.door_window_sensor
      from: 'off'
      platform: state
      to: 'on'
    action:
      - data:
          entity_id: camera.camera_1
          filename: /tmp/snapshot1.jpg
        service: camera.snapshot
      - data:
          data:
            images:
            - /tmp/snapshot1.jpg
          message: oki
          title: example
        service: notify.mail_1

This automation put the image in the body of the email, and not as an attachment.

Do you know how to put it only in attachment ?

For information, my notify.mail_1 is like that :slight_smile:

notify:
  - name: Mail 1
    platform: smtp
    server: smtp.gmail.com
    port: 587
    timeout: 15
    sender: [email protected]
    encryption: starttls
    username: [email protected]
    password: password
    recipient:
      - [email protected]
    sender_name: Home Assistant 

Thanks !

1 Like

I tried with attachment instead of images, but it didn’t work. Same with files instead of images.
Any clue to add attachment ? (not on the body/inline) ?

Thanks

Hello,

Could I try with a python script ? and a shell command ?

Please, I really would appreciate a help/tip on it :slight_smile:

Thanks

Hi @bonilla,

I’m just wondering if you found a solution to have the image attached to the message.

Many thanks.

Hi @wochen welcome on home assistant community !

Yes, here you go!

    service: notify.email
    data_template:
      title: 'Someone is here'
      message: "Who is it?"
      data:
        images:
          - /tmp/snapshot1.jpg
          - /tmp/snapshot2.jpg
          - /tmp/snapshot3.jpg
          - /tmp/snapshot4.jpg
          - /tmp/snapshot5.jpg
          - /tmp/snapshot6.jpg
          - /tmp/snapshot7.jpg
          - /tmp/snapshot8.jpg


        html: >
          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
          <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
            <head>
              <meta charset="UTF-8">
              <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
              <meta name="viewport" content="width=device-width, initial-scale=1.0">
              <title>Motion detected in the flat</title>
              <style type="text/css">
                h1,h2,h3,h4,h5,h6 {
                font-family:Arial,sans-serif;
                }
              </style>
            </head>
            <body>
              <h1>Motion detected</h1>
              <img style="width: 100%; max-width: 640px;"  alt="Image from Flat camera" src="cid:snapshot1.jpg" />
              <img style="width: 100%; max-width: 640px;"  alt="Image from Flat camera" src="cid:snapshot2.jpg" />
              <img style="width: 100%; max-width: 640px;"  alt="Image from Flat camera" src="cid:snapshot3.jpg" />
              <img style="width: 100%; max-width: 640px;"  alt="Image from Flat camera" src="cid:snapshot4.jpg" />
              <img style="width: 100%; max-width: 640px;"  alt="Image from Flat camera" src="cid:snapshot5.jpg" />
              <img style="width: 100%; max-width: 640px;"  alt="Image from Flat camera" src="cid:snapshot6.jpg" />
              <img style="width: 100%; max-width: 640px;"  alt="Image from Flat camera" src="cid:snapshot7.jpg" />
              <img style="width: 100%; max-width: 640px;"  alt="Image from Flat camera" src="cid:snapshot8.jpg" />




          </html>
1 Like

Hi @bonilla,
thank you for sharing this!

Cheers.

This looks good, I have more than one camera however, can I still do this?

Hi, thanks for your code. But in my case it does not work. I receive the email but without an image. Only text. Do I have to prepare something when I use the service camera.snapshot?
First I tried this with iOS notification but to do so the camera must be accessible from the internet.
I hope its not the same with email notification.
that’s my code

hund:
  sequence:
  - service: camera.snapshot
    data:
      entity_id: camera.kamera
      filename: /tmp/snapshot1.jpg
  - delay: 
      seconds: 5 
      
  - service: notify.email
    data:
      message: Überwachungskamera
      data:
        images:
        - /tmp/snapshot1.jpg
        html: >
          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
          <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
            <head>
              <meta charset="UTF-8">
              <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
              <meta name="viewport" content="width=device-width, initial-scale=1.0">
              <title>Motion detected in the flat</title>
              <style type="text/css">
                h1,h2,h3,h4,h5,h6 {
                font-family:Arial,sans-serif;
                }
              </style>
            </head>
            <body>
              <h1>Motion detected</h1>
              <img style="width: 100%; max-width: 640px;"  alt="Image from Flat camera" src="cid:snapshot1.jpg" />
              




          </html>