hargata / lubelog

LubeLogger is a web-based vehicle maintenance and fuel mileage tracker
https://lubelogger.com
MIT License
1.11k stars 57 forks source link

[Feature] reminders sending smtp emails #40

Closed Unkn0wnCreator closed 9 months ago

Unkn0wnCreator commented 9 months ago

As the title says

hargata commented 9 months ago

I'm thinking of exposing an API endpoint that you can hit that will return a list of reminders for a vehicle. You can then setup a script or something that hits this endpoint and if there are reminders you're looking for you can configure your script to send an email.

ionyx0 commented 9 months ago

I can take a crack at this... I've not done much in .NET in quite a while (Java is my daily language) so it may be slow going.

hargata commented 9 months ago

@ionyx0 my concern with this primarily is that it is going to require a service that runs on an interval in the background while the app is running. Whereas if I add an api endpoint then any service can hit this endpoint which will return a list of reminders and their urgency, check if there are any reminders, and then perform whatever action is required such as sending emails, etc.

ionyx0 commented 9 months ago

That's true... Possibly just the structure for sending emails for my part, then. A service seems less than trivial and will require more planning and expertise than I have.

hargata commented 9 months ago

@ionyx0 I don't think there should be any code for sending emails within the app itself. The way reminders are currently loaded right now is on page load, and if there are any very urgent or past due reminders, it will turn the Reminder icon yellow.

If we add a SMTP method that will send emails every time this method detects "Very Urgent" or "Past Due" reminders, it will send an email to the user on every page load and every tab load, which is probably not a desired behavior.

I'm currently working on an API controller that will provide some endpoints that can help other users automate features such as sending emails and whatnot.

hargata commented 9 months ago

API Endpoints have been added as of the latest release, if you have auth set up it takes Basic Auth with the same credentials. First run the /api/vehicles endpoint to get a list of vehicles image Then use the vehicle id and query /api/vehicle/reminders with vehicleId as the param image This endpoint will return a list of reminders and their urgency.

Full list of endpoints(all GET currently) is available on /api

You can set up a script or a service that runs on an interval that queries the list of reminders for each vehicle, and can then relay that to a SMTP service that will shoot you an email

fftux commented 9 months ago

Not sure if this would be easier or not, but adding support for ntfy would provide the ability for push notifications. I believe you could implement this relatively simply in the UI with a toggle to enable, a field to specify the url for the ntfy server to use, and a field for the topic.

https://docs.ntfy.sh/publish/

hargata commented 9 months ago

I have added an API endpoint that will automatically pull all vehicle's collaborators' email address and send them reminders based on the urgency. Note that you have to use the Root User's credentials to execute this endpoint. Example bash script:

curl -n -u "rootUser:rootPassword" --location "https://lubelogger.mydomain.com/api/vehicle/reminders/send?urgencies=NotUrgent&urgencies=VeryUrgent&urgencies=Urgent&urgencies=PastDue"

You can schedule this to run once a day using a cron job.

This issue will now be closed.