everything works perfectly!! thanks for your patience
No problem, glad to hear it is working for you
thanks again for the help! I have only two things to ask… the first is that I find the smtp2 folder on media which is always full of images that I have to delete after every day but this is not a big problem… the problem is that when I get the notification on the phone and I open it directs me to the home screen of the home assistant app and therefore I have to go manually to the media folder and look for the file corresponding to the date and time but which with the presence of so many files is difficult to find … there is no is there a way to open the notification and direct me to the full screen image?
I researched this a little, found this post:
How to open /media image via relative URL in clickAction?
So I added a ‘clickAction’ in my automation, just below the ‘image’ that was already there, like so:
data:
image: >-
{{trigger.payload_json.mime_parts|selectattr('saved_file_name','defined')|map(attribute='saved_file_name')|first|replace('/share','/media')}}
clickAction: >-
{{trigger.payload_json.mime_parts|selectattr('saved_file_name','defined')|map(attribute='saved_file_name')|first|replace('/share','/media')}}
And it looked like it was going to work, but then all I got was a ‘401 unauthorized’ which is what they OP was saying in that post.
So then I followed the open issues on it:
https://github.com/home-assistant/android/issues/2684
https://github.com/home-assistant/android/pull/3232
And it looks like they put a fix into the current beta release of the Android app:
https://github.com/home-assistant/android/releases/tag/beta-3232-aaef2549
I downloaded the .apk for that beta & tried it, still didn’t work.
So at this time it looks like there are provisions for doing something like this, but it doesn’t currently work, sorry.
As for cleaning up the share folder with all the images, I have a scheduled automation that runs a Shell Command service nightly.
The shell command itself is simple:
find /share/smtp2mqtt/ -maxdepth 1 -type f -mtime +1 -exec rm {} \;
This seems to work well, keeps the files trimmed down to about a couple days’ worth.
Ok thanks!I hope this problem is solved because it would be a very useful thing
is there a possibility to rename the files in order to be more recognizable? for example ordering them with a starting number…it’s really hard to find the picture by phone because they are ordered randomly
Apologies for taking so long to reply to this, been very busy lately.
I did think about this for a bit & decided against modifying the add-on to re-name since others may want something different and it could get out of hand trying to find a way to make it generic enough for everyone.
Instead I had another thought - I believe it would be relatively simple to use the Shell Command integration to rename the files after they are written to disk.
It could be an action in the automation to call a shell command that simply does an mv from the current file name to whatever file name you wish.
Probably do that early-on, then reference the new file name in the notification service (since the old file name won’t exist anymore after the mv).
So, it looks like my camera updated its firmware and I can get smtp to Gmail to work. However, when I try this addon I’m getting some errors. The camera throws the same error 400, but there’s some new stuff in the logs now:
/usr/lib/python3.10/site-packages/aiosmtpd/smtp.py:372: UserWarning: Requiring AUTH while not requiring TLS can lead to security vulnerabilities!
warn("Requiring AUTH while not requiring TLS "
auth_required == True but auth_require_tls == False
('192.168.168.125', 61559) unrecognised: e#
Is there anything I can do to hopefully get this working?
I’m getting the exact same problem. I tried to configure this add-on with with my Reolink Argos Eco camera but every time I send a test email, I get a 400 error and this is the only message in the logs.
I found the problem with my Reolink Argos Eco camera.
It turns out that the camera sends an SMTP “HELO” message instead of “EHLO”. The SMTP library used by this add-on(“aiosmtpd”), considers the “HELO” not to be extended_smtp and later rejects the “AUTH LOGIN” command from the camera.
I don’t think there is an easy workaround other than modifying the “aiosmtpd” lib to force the extended_smtp mode for “HELO” as well.
Thank you for digging into the aiosmtp library & uncovering the difference between EHELO and HELO, that helps!
I can see in the code of the aiosmtp library where it is doing what you say, I can also see where it may be possible to override the HELO handler in this add-on to ‘turn on’ the extended smtp features, which may possibly be a work-around.
However, I am limited on time. I will try to make an effort in the next week or-so, no guarantees.
In the meantime, I’ll re-iterate my usual go-to - I know the password field in the camera web UI is marked required but I own several different Reolink devices and they all let me both test & save email settings when I leave that field blank and I am able to use this add-on with ‘SMTP Auth Required’ turned off, with no issues.
Could you please try again to leave the password field blank? Don’t forget to turn off SMTP auth in the add-on configuration as well.
Thanks again for doing the research!
I ran into this same HELO vs EHLO issue trying to use this add-on for a Cummins standby generator that sends events as emails.
As suggested the problem was fixed by adding the following method to SMTP2MQTTHandler:
async def handle_HELO(self, server, session, envelope, hostname):
session.extended_smtp = True
session.host_name = server.hostname
status = '250 {}'.format(server.hostname)
return status
Good evening, I need help, I’ve been trying for a long time but I can’t get the images from my camera to publish on mqtt… With PowerShell Test I can publish but when my camera send image email I get the following error:
2024-03-21 23:16:02,254 - smtp2mqtt - DEBUG - d397f285 - SKIP publish attachment data
2024-03-21 23:16:02,255 - smtp2mqtt - INFO - d397f285 - Saving attachment to /share/smtp2mqtt/[email protected]/d397f285_6129747_2024032123160201.jpg
2024-03-21 23:16:02,261 - smtp2mqtt - DEBUG - d397f285 - SKIP publish attachment data
2024-03-21 23:16:02,261 - smtp2mqtt - INFO - d397f285 - Saving attachment to /share/smtp2mqtt/[email protected]/d397f285_None
(‘192.168.1.11’, 46242) SMTP session exception
Traceback (most recent call last):
File “/usr/lib/python3.10/site-packages/aiosmtpd/smtp.py”, line 741, in _handle_client
await method(arg)
File “/usr/lib/python3.10/site-packages/aiosmtpd/smtp.py”, line 1460, in smtp_DATA
status = await self._call_handler_hook(‘DATA’)
File “/usr/lib/python3.10/site-packages/aiosmtpd/smtp.py”, line 473, in _call_handler_hook
status = await hook(self, self.session, self.envelope, *args)
File “/app/smtp2mqtt.py”, line 127, in handle_DATA
f.write(attachment.get_content())
TypeError: a bytes-like object is required, not ‘str’ <
This is one great addon! Thank you mate.
I do have a question though. Would it be possible to make an option to set a directory where attachments should be saved? It now defaults to share directory, which might be on SD card and with alot of attachments, this would not be best. If you could set a save directory on lets say network share, that would be awsome.
Thank you for a response.
V.
For anyone who might feel the need, I have ported the Add-On to be a standalone docker image. I had the need to run two instances of this addon, because I have some services that cannot handle smtp auth without tls (Authelia to be specific) while others are happy without tls combined with smtp auth…
The service has been tested with Authelia, Vaultwarden, OpenMediaVault and Opnsense/Monit SMTP-Notifications. All SMTP Messages were successfully transformed to MQTT Messages for further use in Home Assistant. (I am goingt to use it for Push Messages to the Companion App btw…)
Thanks bcastellucci for your work on this!
A basic docker-compose.yaml could look like this. Modify the settings as needed with the environment variables, furthermore the image is multi-arch, so choose it according your needs:
services:
smtp2mqtt:
image: ghcr.io/boecks/docker-smtp2mqtt-amd64:latest
container_name: smtp2mqtt
ports:
- 25:25
environment:
DEBUG: true
SMTP_LISTEN_PORT: 25
SMTP_AUTH_REQUIRED: true
SMTP_RELAY_HOST: None
SMTP_RELAY_PORT: None
SMTP_RELAY_USER: None
SMTP_RELAY_PASS: None
SMTP_RELAY_TIMEOUT_SECS: 60
SMTP_RELAY_STARTTLS: false
MQTT_HOST: mosquitto
MQTT_PORT: 1883
MQTT_USER: user
MQTT_PASS: password
MQTT_TOPIC: smtp2mqtt
PUBLISH_ATTACHMENTS: true
SAVE_ATTACHMENTS: false
SAVE_ATTACHMENTS_DIR: /share/smtp2mqtt
volumes:
- ./attachments:/share
restart: always
logging:
driver: json-file
options:
max-size: 1m
max-file: 1
I’m trying to set up this add-on, I got everything installed ok but when I configure my NVR to send e-mail I get an error in the NVR and in the the add-on I get this:
('192.168.0.70', 59987) unrecognised: DGVZDEB0ZXN0LMNVBQ==
In my NVR I need to set at least the user name I used [email protected]