Open clinique opened 2 months ago
AFAICT there is no way to validate user/pass before actually sending a mail. So the best thing that can be done is set the thing to UNKOWN at startup. If that is all you require i can make a PR, but it is hardly changing anything to the binding behaviour.
Yes, I imagined that it was the pitfall. I think it would be better to leave it UNKNOWN until the connection is definitively known as working.
I know that this is currently not implemented, but IMO a thing that is not ONLINE
should not receive commands from the framework (similar to UNINITIALIZED
). This would also greatly simplify binding development, because connection state and similar would not need to be checked when processing a command. So I would vote against changing it.
Instead we could add code like https://stackoverflow.com/questions/49867860/java-mail-api-credentials-verification to initialize()
and set the thing to OFFLINE
.
Even if that would be implemented I would expect that an UNKNOWN state would allow you to send commands.
However, the link you provided may be a good solution. Busy with some other PR’s but might come back to this.
a thing that is not
ONLINE
should not receive commands from the framework (similar toUNINITIALIZED
)
+1
It would be weird to try to send an email when the thing is not online.
I would say implement an optional (!!) credential check at the beginning if you need such feature. Beware that repeated authentications, especially incorrect ones, could get you banned from the mail server if it has an overzealous security, e.g. fail2ban or something. And this could happen if one were to restart openhab too often. So please make this an optional config.
a thing that is not
ONLINE
should not receive commands from the framework (similar toUNINITIALIZED
)+1
It would be weird to try to send an email when the thing is not online.
I would say implement an optional (!!) credential check at the beginning if you need such feature. Beware that repeated authentications, especially incorrect ones, could get you banned from the mail server if it has an overzealous security, e.g. fail2ban or something. And this could happen if one were to restart openhab too often. So please make this an optional config.
Why is it weird to try to send a mail while the thing status is UNKOWN?
Checking the credentials on binding start and set the thing state accordingly would be good great. Don't see why this should be optional, as under what circumstances would one restart the binding that often to get a ban?
While coding a rule that sends mails, a mistake is easily made, never seen a user complain about a ban. This mechanism would even protect you for those mistakes. Or what am i missing?
Unfortunately it's not that easy. Imagine you have a power outage. openHAB might be faster in restarting than your internet router, so the credentials check will fail because there is no connection to the server. if you never try to re-connect, you'll always stay in OFFLINE mode.
@lsiepel Isn't it possible to capture the response of the SMTP server ? In case of a wrong username/password it would be 535 5.7.8 Authentication credentials invalid. during the handschake with the SMPT Server ? The response could be logged. @J-N-K If there is no internet access, a connection to the SMTP server will not open. Therefore the test loops (every x seconds) until it can. Until succesfull opening a connection the status is offline.
From the tests I made, it appears that SMTP thing status is ONLINE while credentials are tested only upon expedition of a mail.