Sendmail - Send email and text notifications, (notification device) no local server needed

I've only been using it to send door opened, laundry done notifications...can't imagine it's been more than 10-20 at most.

Checked my texts and it's about 6 texts. So nothing is being overwhelmed...

ya that cannot be it.. but put a new version up just now anyway with extra checking for the quit case to make sure the sockets are closed. they should be closed anyway as they close even in an error case. but doesnt hurt.

if you were saying you had 1000 emails i would say maybe. .but even if it never closed everythign 6 sockets would not cause an issue.

1 Like

As a side note anyone else use at&t? Do you know of a way to NOT have each message show up like it came from a different phone number. Really a pain in the ■■■. Would obviously like them all under one thread on the phone.

Port 25 is the historical standard SMTP port when clear text in transmission wasn't considered a problem and spammers didn't yet exist. You may find now that different ports are used, also depending on whether you are a mail transfer agent or a mail user agent (Hubitat would be the latter).

As I said above, sending email from Hubitat is going to work best when you have a more fully featured mail server that you control that you can send to/relay through. "no local server needed" may be challenging for many to get to work.

1 Like

well it works without a local server for spectrum and comcast so that are two of the biggest right there.

2 Likes

You can't read too much into the fact that it has worked in the cases you've tested. There are a lot of reasons that it will work reliably in some cases, but completely fail in others. These include differences in hub loading, size of the message, internet connection speed, connection latency, ISP server load, etc.

1 Like

By the way, if it wasn't clear from the earlier message, simultaneous invocations will also result in leakage of telnet connections (sockets).

I'm not trying to rain on your parade, but the global variable to store session state is a killer... you should either block simultaneous invocations or move to some form of session variable to keep track of connection state.

Or perhaps even a parent device with a pool of child devices to do the actual work... (Now there's a coding project :slight_smile:) .

there are no session variables i know of for degvice drivers i can find in documentation state is also not thread safe..

Make one. You can construct one using a sequential counter appended to a fixed variable name. But don't forget to clean up (delete) the state when the session is done. You probably want a timer and/or an initialize() call as a backup...

3 Likes

i am not sure it is possible becasue the system ie mail/telnet is asynch so when a response comes back i dont think there is a way to know what session it is for..

also there is no socket id.. you just open and then call send or closeconnection there is no socket parameter etc. it appears that the telnet interface is non-reentrant so even if my variable was it would not work..

for people that want multiple emails at the same time.. just set up multiple devices for now.. if you know its going to hjappend.. i have never had issues but i dont have 8 million rules set up to send emails either

That doesn’t solve the issue tho. you would be better off implementing a basic serial queuing system.

yes that would work forcing one to wait while the other finishes.. that would be the only solution..

3 Likes

Yep, you're right. No closure on telnet callbacks. Bummer.

Now, about that pool of child devices...
:slight_smile:

new version 2.4 that does a limited type of serializing/queueing

If the state variable appears to be in a state where an existing message is in the middle of being sent or it failed and left state variable in a weird state (not likely)

it will wait for one minute. than try again..
If state variable is still screwed up it will force close (closeConnection) any existing connection reset variable and continue on..

I have tried it with 4 conseq. and all got delivered.

5 Likes

Nice work sir!

Damn...things are moving quickly here.

Want to say it's working perferctly for me, using a Spectrum email account that I was not using at all (hadn't touched for years). Resurrected the email account for this and texts are arriving as expected. I do appreciate the excellent discussion and updates, really nice.

2 Likes

Ok, there is an issue when used with a mail Relay - the first email I sent worked but showed an error at the end:

dev:4952020-11-18 02:48:25.428 pm debugtelnetStatus: receive error: Stream is closed
dev:4952020-11-18 02:48:25.402 pm debugquit
dev:4952020-11-18 02:48:24.896 pm debug.
dev:4952020-11-18 02:48:24.382 pm debug
dev:4952020-11-18 02:48:23.869 pm debugtest
dev:4952020-11-18 02:48:23.355 pm debug
dev:4952020-11-18 02:48:22.842 pm debugDate: Wed Nov 18 14:48:19 AEDT 2020
dev:4952020-11-18 02:48:22.327 pm debugSubject: Home Activity Event

the next email I sent failed even tho the first had successfully been sent and recieved:

dev:4952020-11-18 02:48:45.058 pm debugExisting state (other) indicates last run did not complete. Waiting 1 minute then trying again!
dev:4952020-11-18 02:48:45.040 pm debugInitial state found: (other)
dev:4952020-11-18 02:48:45.035 pm debug-------> In lgk sendmail Version (2.4)

and the 3rd email I sent (intentionally sent while #2 was trying to send) worked but finished with the same error:

dev:4952020-11-18 02:49:55.279 pm debugtelnetStatus: receive error: Stream is closed
dev:4952020-11-18 02:49:55.267 pm debugquit
dev:4952020-11-18 02:49:54.762 pm debug.
dev:4952020-11-18 02:49:54.248 pm debug
dev:4952020-11-18 02:49:53.742 pm debugtest3
dev:4952020-11-18 02:49:53.229 pm debug
dev:4952020-11-18 02:49:52.717 pm debugDate: Wed Nov 18 14:49:49 AEDT 2020
dev:4952020-11-18 02:49:49.650 pm debugin sendData
dev:4952020-11-18 02:49:49.646 pm debugIn helo/Password case
dev:4952020-11-18 02:49:49.643 pm debugGot server response 250 value = msn.com lastCommand = (helo)
dev:4952020-11-18 02:49:49.638 pm debuglastCommand = helo
dev:4952020-11-18 02:49:49.635 pm debugIn parse - 250 msn.com
dev:4952020-11-18 02:49:49.103 pm debughelo [192.168.1.170]
dev:4952020-11-18 02:49:49.100 pm debugIn initialConnect case
dev:4952020-11-18 02:49:49.097 pm debugGot server response 220 value = msn.com lastCommand = (initialConnect)
dev:4952020-11-18 02:49:49.093 pm debuglastCommand = initialConnect
dev:4952020-11-18 02:49:49.090 pm debugIn parse - 220 msn.com ESMTP Postfix
dev:4952020-11-18 02:49:49.018 pm debugConnecting to 192.168.1.104:25
dev:4952020-11-18 02:49:49.014 pm debugFound ok initial state... going on!
dev:4952020-11-18 02:49:49.011 pm debugInitial state found: (Force Closed)
dev:4952020-11-18 02:49:49.004 pm debug-------> In lgk sendmail Version (2.4)

FWIW, here are logs from a recent send that was successful. One text sent from the device page.

it is not really an error if it just says stream closed becuase of the async nature responses can come in after the socket is already closed and the message has been sent

what was the error state for the one that failed.. do you have the entire log for that message..

the telnetstatus message is called internally but the hub not me.. it is most likely being called where i have an extra closeConnection where the connection is already closed.. i need to check if it is open first.. not sure how to do that..

ok makes sense.

here is the full test 2 and test 3 log section:

dev:4952020-11-18 02:49:55.870 pm debugIn fall through case looking for 250 or 354 or 221 (bye)
dev:4952020-11-18 02:49:55.867 pm debugGot server response 221 value = 2.0.0 lastCommand = (other)
dev:4952020-11-18 02:49:55.863 pm debuglastCommand = other
dev:4952020-11-18 02:49:55.860 pm debugIn parse - 221 2.0.0 Bye
dev:4952020-11-18 02:49:55.857 pm debugIn fall through case looking for 250 or 354 or 221 (bye)
dev:4952020-11-18 02:49:55.854 pm debugGot server response 250 value = 2.0.0 lastCommand = (other)
dev:4952020-11-18 02:49:55.850 pm debuglastCommand = other
dev:4952020-11-18 02:49:55.847 pm debugIn parse - 250 2.0.0 Ok: queued as 0B9E971E002B
dev:4952020-11-18 02:49:55.844 pm debugIn fall through case looking for 250 or 354 or 221 (bye)
dev:4952020-11-18 02:49:55.840 pm debugGot server response 354 value = End lastCommand = (other)
dev:4952020-11-18 02:49:55.836 pm debuglastCommand = other
dev:4952020-11-18 02:49:55.833 pm debugIn parse - 354 End data with .
dev:4952020-11-18 02:49:55.828 pm debugIn fall through case looking for 250 or 354 or 221 (bye)
dev:4952020-11-18 02:49:55.825 pm debugGot server response 250 value = 2.1.5 lastCommand = (other)
dev:4952020-11-18 02:49:55.821 pm debuglastCommand = other
dev:4952020-11-18 02:49:55.816 pm debugIn parse - 250 2.1.5 Ok
dev:4952020-11-18 02:49:55.812 pm debugIn fall through case looking for 250 or 354 or 221 (bye)
dev:4952020-11-18 02:49:55.808 pm debugGot server response 250 value = 2.1.0 lastCommand = (sendmessage)
dev:4952020-11-18 02:49:55.804 pm debuglastCommand = sendmessage
dev:4952020-11-18 02:49:55.800 pm debugIn parse - 250 2.1.0 Ok
dev:4952020-11-18 02:49:55.279 pm debugtelnetStatus: receive error: Stream is closed
dev:4952020-11-18 02:49:55.267 pm debugquit
dev:4952020-11-18 02:49:54.762 pm debug.
dev:4952020-11-18 02:49:54.248 pm debug
dev:4952020-11-18 02:49:53.742 pm debugtest3
dev:4952020-11-18 02:49:53.229 pm debug
dev:4952020-11-18 02:49:52.717 pm debugDate: Wed Nov 18 14:49:49 AEDT 2020
dev:4952020-11-18 02:49:52.201 pm debugSubject: Home Activity Event
dev:4952020-11-18 02:49:51.683 pm debugTo: <to>
dev:4952020-11-18 02:49:51.168 pm debugFrom: <from>
dev:4952020-11-18 02:49:50.664 pm debugDATA
dev:4952020-11-18 02:49:50.161 pm debugRCPT TO: <to>
dev:4952020-11-18 02:49:49.654 pm debugMAIL FROM: <from>
dev:4952020-11-18 02:49:49.650 pm debugin sendData
dev:4952020-11-18 02:49:49.646 pm debugIn helo/Password case
dev:4952020-11-18 02:49:49.643 pm debugGot server response 250 value = msn.com lastCommand = (helo)
dev:4952020-11-18 02:49:49.638 pm debuglastCommand = helo
dev:4952020-11-18 02:49:49.635 pm debugIn parse - 250 msn.com
dev:4952020-11-18 02:49:49.103 pm debughelo [192.168.1.170]
dev:4952020-11-18 02:49:49.100 pm debugIn initialConnect case
dev:4952020-11-18 02:49:49.097 pm debugGot server response 220 value = msn.com lastCommand = (initialConnect)
dev:4952020-11-18 02:49:49.093 pm debuglastCommand = initialConnect
dev:4952020-11-18 02:49:49.090 pm debugIn parse - 220 msn.com ESMTP Postfix
dev:4952020-11-18 02:49:49.018 pm debugConnecting to 192.168.1.104:25
dev:4952020-11-18 02:49:49.014 pm debugFound ok initial state... going on!
dev:4952020-11-18 02:49:49.011 pm debugInitial state found: (Force Closed)
dev:4952020-11-18 02:49:49.004 pm debug-------> In lgk sendmail Version (2.4)
dev:4952020-11-18 02:49:49.001 pm debugExisting State still (null)... Last message appears to have failed. Force closing existing connection and sending new message.
dev:4952020-11-18 02:49:48.997 pm debugStaring up... Initial state found: (other)
dev:4952020-11-18 02:48:48.984 pm debugExisting state (other) indicates last run did not complete. Waiting 1 minute then trying again!
dev:4952020-11-18 02:48:48.980 pm debugInitial state found: (other)
dev:4952020-11-18 02:48:48.977 pm debug-------> In lgk sendmail Version (2.4)
dev:4952020-11-18 02:48:45.058 pm debugExisting state (other) indicates last run did not complete. Waiting 1 minute then trying again!
dev:4952020-11-18 02:48:45.040 pm debugInitial state found: (other)
dev:4952020-11-18 02:48:45.035 pm debug-------> In lgk sendmail Version (2.4)