SMTP - unknown MIME type

I get an error on some of my JPEG files when trying to attach in an email using the SMTP component.
I have five cameras and get the files using a wget shell_command. One of the cameras works fine, the others does not.
HASS log:
17-03-01 19:43:15 WARNING (Thread-1) [homeassistant.components.notify.smtp] Attachment /tmp/camera_kaelder_stort_rum.jpg has an unkown MIME type. Falling back to file

Output using “file” on a Linux os:

This one works:
JPEG image data, JFIF standard 1.01, aspect ratio, density 1x1, segment length 16, Exif Standard: [TIFF image data, big-endian, direntries=3, datetime=2017:03:01 20:50:33], baseline, precision 8, 1280x720, frames 3

This one does not:
JPEG image data, baseline, precision 8, 1920x1080, frames 3

MIME info from Thunderbird:

This one works:
Content-Type: image/jpeg
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-ID:

This one does not:
Content-Type: application/octet-stream; Name="/tmp/camera_kaelder_stort_rum.jpg"
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="/tmp/camera_kaelder_stort_rum.jpg"

Is this a bug or am I doing something wrong?

I made a script that downloads the images using “wget” and run a “convert” from .jpg to .jpg and that seem to solve the issue with the unknown mime type.

1 Like

Hi,

I have the same problem. Do you mind to share that convert script?

Is it just like this: convert image.jpg image.jpg

EDIT: Got it working. thx :wink:

E.

Sure :slight_smile:
Here’s for everyone else.

shell_command:
  camera_wget_convert: sh /config/camera_wget_convert.sh

Use this action in an automation:
action:

  • service: shell_command.camera_wget_convert

Script file in Home Assistant folder:
10.0.1.2:8123 is my Home Assistant. 127.0.0.1 does not seem to work.

camera_wget_convert.sh

#!/bin/bash
wget -q -O /tmp/camera_forhave.jpg http://10.0.1.2:8123/api/camera_proxy/camera.forhave
wget -q -O /tmp/camera_kontor.jpg http://10.0.1.2:8123/api/camera_proxy/camera.kontor
convert /tmp/camera_forhave.jpg /tmp/camera_forhave2.jpg
convert /tmp/camera_kontor.jpg /tmp/camera_kontor2.jpg

You can even do this:

convert /tmp/camera_forhave.jpg /tmp/camera_forhave.jpg

I use the same name so the original will be overwritten by the new.

E.

I’m running a Pi with Python 3.6 in Venv, couldn’t get this to work on either of my setups (with varying cameras), probably permission / folder issues. It was happening with smtp email and pushbullet.

I installed imagemagik;

sudo apt install imagemagick

There were some libraries I had to add on one install the other went without issue.

I had issues getting the shell file to run with permissions so just added this shell command, I found it easier for the time being to name images differently so I could check it was working by rewriting;

camera_wget_convert1:  'convert /home/homeassistant/.homeassistant/tmp/rearcampic0.jpg -quality 90 /home/homeassistant/.homeassistant/tmp/rearcampic1.jpg'

I have a separate shell.yaml so the above dropped straight in here and in the automation this shell command ran after I captured the image with camera.snapshot in my automation, as below, saved me adding urls for capturing to shell command;

action:
  - service: camera.snapshot
    data:
      entity_id: camera.rearcam
      filename: /home/homeassistant/.homeassistant/tmp/rearcampic0.jpg
  - delay: 00:00:02
  - service: shell_command.camera_wget_convert1
  - delay: 00:00:04      
  - service: notify.email_notification
    data:
      message: Door Opened
      title: Door Opened
      data:
      #html: <h4>Movement in Dining Room</h4>
        images:
         - /home/homeassistant/.homeassistant/tmp/rearcampic1.jpg

Hello,
My return code is: convert bash not exist
Any idea

In hassio don’t work due command ‘convert’ in unknown

Correct, you have to install ImageMagick + fonts after you update. I made a script to install it every time HassIO is started:

- alias: Startup
  initial_state: true
  trigger:
    platform: homeassistant
    event: start
  action:
    - service: shell_command.imagemagick

shell_command:
  imagemagick: /bin/bash /config/script/imagemagick.sh

Script (imagemagick.sh)

#!/bin/bash

logger Install ImageMgick & fonts
apk --update add imagemagick && apk --no-cache add msttcorefonts-installer fontconfig && update-ms-fonts && fc-cache -f
  
exit 0

E.

Thanks for this thread :slight_smile:
ImageMagick convert solved my problem of SMTP complaining of unknown MIME type!

Suddenly I’ve started to get the same. I don’t want to mess up with some extra software so I submitted an issue Unknown MIME Type in SMTP only when fired from automation · Issue #49216 · home-assistant/core · GitHub Funny thing that running the same part for developer tools works ok.

I am getting the same warning. It also says “falling back to file”. In my case, I have also have the same message as html. It does seem that I am receiving the message in the html body.