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

Insurance companies are usually pretty good in Australia as we have some very strict Consumer Protection laws - but if there's a grey area, they will try to exploit it.

1 Like

My wife and I are planning a long visit down under in a couple of years...when we arrive we'll get together for a beer and "insurance griping session." :slight_smile:

2 Likes

:smiley: I'm in Melbourne, we have some great pubs in the city I could take you to. :beers:

2 Likes

i actually tried to do a version with a full .. queue using the state variables but aparently they are not re-entrant even though they kinda seem to be workin in this limited case..
i would put stuff in the queue. after it would show it.. and also show it when i run the initial function but when the getnextitem off of queue was called it would show empty..

bummer. have to go with this for now.. if you try to send more than 3 in a 20-30 sec range it will most likely drop one.

2 Likes

I believe the way state variables are working from my observations is that they are stored globally with the device, but when the device code gets called it is making a local copy of the state variables for you to use.. Not sure when they get rewritten to the device handler maybe on exit.
But so if i am running and i make changes to the queue fine i can see them

but in the meantime if another instance starts up (ie another email comes in) and it adds it to the queue it is only in its instance and when the first running one then finishes the email and goes to look at the queue it is not seeing the elements the other instance added.

@kahn-hubitat

FYI, not sure if it's applicable to Sendmail, but wanted to share that there was an update to HE Mail today that might be interesting to you.

i am not sure what the point of that is becuase the rest of the code does not really support multiple instances/emails being sent at once anyway.. It would have to be rewritten like i was trying with some sort of queueing method..

2 Likes

I agree that some sort of queuing would be a better way to go...

2 Likes

ya i am still searching for a way to implement queueing that works in a device handler with multiple instances running. you would think the state variables or attributes would but as i found out not really. Apparently they are not really true globals.. but local copies that are rewritten to the global pool at some point..

1 Like

The system is async by default. Certainly the actual sending of message code is sequential but the calling of it is not. This update tries to mitigate that by attempting to acquire a semaphore (timeout 5000 milliseconds) before sending stuff. The thinking is to try and throttle things if incoming gets too fast. Some people were getting skips - whether or not it will be effective as you mention remains to be seen.

1 Like

ok peeps new version. i have tested it with up to 10 concurrent messages

v 2.4.3 true concurrency and queueing using a thread safe data structure concurrentlinkedqueue and also mutex (thanks to erktrek)
tested with up to 10 messages
When one message finishes it checks the queue, and delivers any other remaining.. also schedules a rerun when busy and one is added to the queue.
also serialize the setting and checking of the state.lastCommand as this is used to keep track of the async status of the commands

here is the jist of it

import java.util.concurrent.Semaphore
import java.util.concurrent.TimeUnit
import groovy.transform.Field
import java.util.concurrent.ConcurrentLinkedQueue

@Field static java.util.concurrent.Semaphore mutex = new java.util.concurrent.Semaphore(1)
@Field static java.util.concurrent.Semaphore lastStateMutex = new java.util.concurrent.Semaphore(1)

@Field static lqueue = new java.util.concurrent.ConcurrentLinkedQueue()

also figured out how to have multiple concurrent runIn commands scheduled without one overwriting the other which would cause messages to be lost with the secret command:

runIn(30,"processQueue", [overwrite: false])

Lots of changes.. let me know if you see any issues.

4 Likes

Nice work!

I assume this is running ok in the new updates as I have not updated yet due to various cluster *****
regarding presence sensors and dashboard tile links..

Will give you guys some time to work out the kinks.

v 2.5 changes were enough to signify new version. Found one bug in last one when reviewing code. a synchronize inside a synchronize on same semaphore.
Did not seem to be causing issues so I assume the system is smart enough to avoid it but fixed anyway.

1 Like

I've been on .141 since release without issues - .142 broke almost everything tho. :man_facepalming:

No kinks here! Very nice work sir! :sunglasses:

1 Like

Dayum! :slight_smile: Wow... 2.2.4.143 and updated Sedmail with queuing! I should spend the afternoon at my mom's house more often, great things happen whilst we whiled the time away.

Thanks very much for the update, @kahn-hubitat...I drove home today and opened my garage door and my garage door opened text appeared so quickly that I was surprised by it. Excellent work.

Darn, I forgot, shout-out to @erktrek (big-time troublemaker) as well. :slight_smile:

3 Likes

Good day all.

I'm working on attempting to get this going (lots of caveats, yes). I'm struggling with what to enter for what.

I'm wanting to send emails using my gmail account, but not sure what / how to enter the preferences on the virtual device.

I'm using the following:
Email server: smtp.gmail.com
Port: 587
From: <my gmail account with suffix "@gmail.com">
To: <this is my cell phone using "phone@txt.att.net">
Hostname: smtp.gmail.com
Enable logging: checked
Use authentication on the server: checked
Username: <my gmail account with suffix "@gmail.com">
Password: my gmail account password

When I try a test in "Device Notifications", I see "send failed" as the last command. In the logs, it ends with "Got bad response for auth = 530"

Any ideas what I'm doing wrong?

You can't go directly to Google because of a system limitation preventing the use of authentication. Instead you have to use your ISP's email.

2 Likes

@Noob_using_hubitat

@erktrek has explained why sending email to gmail fails using this integration. I just want to mention that there is another email integration - written by @erktrek that will work for your use case.

@erktrek's integration does require an external device running sendmail (or a sendmail-compatible mailer). Most people use a Raspberry Pi; however, anything running Linux/Unix and capable of running sendmail will work just fine.

3 Likes