hargata / lubelog

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

SMTP issues #517

Open marcogiorgio opened 1 month ago

marcogiorgio commented 1 month ago

Hi, my .env file is as follows:

LC_ALL=it_IT.UTF-8
LANG=it_IT.UTF-8
MailConfig__EmailServer="smtp.sendgrid.net"
MailConfig__EmailFrom="info@mydomain.net"
MailConfig__UseSSL="true"
MailConfig__Port=587
MailConfig__Username="apikey"
MailConfig__Password="mypassword"
#LOGGING__LOGLEVEL__DEFAULT=Error

I am trying to test that the emails are sent out correctly by opening the page https://lubelogger.mydomain.net/api/vehicle/reminders/send?urgencies=NotUrgent while logged in with my root user. I get:

success true
message "Emails sent"

but I don't receive any emails... In facts, my firewall doesn't even show that an outbound connection to port 587 is being made.. I've opened a shell into the container and I am able to reach smtp.sendgrid.net at port 587. Is there a way to debug this? I don't see anything that can help me in the app logs

Thanks

marcogiorgio commented 3 weeks ago

I've re-opened the issue because I initially thought something was wrong from my end but it doesn't seem the case.

hargata commented 3 weeks ago

If there are no logs or errors, that means that the email was flagged and failed by SendGrid's servers because they think it's spam. SendGrid has a very stringent filter because of historical abuse.

I would consider trying a different SMTP provider such as Gmail and see if it works, unfortunately this is beyond our control.

marcogiorgio commented 3 weeks ago

Hi @hargata But I can see from my firewall logs that a connection is made to the sendgrid server if I telnet it from the container shell, whereas when I use the API route, no external connection is made. Furthermore, there is nothing logged in Scalegrid

hargata commented 3 weeks ago

Yeah I'm not sure then. I don't have a sendgrid account to test this with. Does port 465 work?

marcogiorgio commented 3 weeks ago

I don't think the problem is Scalegrid here, I've changed the SMTP config to use a Postfix relay which I am using for services that don't support authentication. Even with this one no emails are sent and no connections are made to the relay... But I still get

success: true
message: "Emails sent"

I've tried with both

MailConfig__Username=""
MailConfig__Password=""

and also I've tried to remove them entirely

hargata commented 3 weeks ago

I'm not sure then, sorry, I can't help you debug this because I don't have your exact setup.

I'll keep your issue open just in case someone else can chime in

marcogiorgio commented 3 weeks ago

Sure, no worries. I'll try to investigate more this weekend

marcogiorgio commented 3 weeks ago

Hi @hargata, I managed to find the problem root cause... Basically when I enabled the authentication feature I didn't notice that the user that you create during this process is not a "real user" (I guess this is just a wrapper for the HTTP basic auth?)... I had to create a real user from the admin page with an email associated to it...

Anyway if I got it right, I think this is a little bit confusing, maybe it would be better to have a "full" user created when you enable authentication. In facts, I was able to create another user using the token registration functionality with the same username as the one I used when I enabled the authentication...

As a results, when I login I don't really know which user I am actually using

johenkel commented 1 week ago

@marcogiorgio I am running into teh same problem it seems. I got the successful API call ( {"success":true,"message":"Emails sent"} ). After reading your comment, I was trying to create a user in the Admin Panel page.

However I do not have a button to create a new user !?

marcogiorgio commented 1 week ago

@johenkel there is no button to create a new user in the admin page. You have to generate a token by clicking on the 'Generate user token' button.

Then you have to logout and click on 'Register' and use that token to crete a new user.

More info here