vaultwarden-backup icon indicating copy to clipboard operation
vaultwarden-backup copied to clipboard

connection refused

Open chrisuhg opened this issue 1 year ago • 8 comments

image

i can make sure the container has access the internet, but why it always connect to localhost ?

chrisuhg avatar May 18 '24 19:05 chrisuhg

It's impossible to get relevant information from the description alone, please provide the logs during the backup.

ttionya avatar May 23 '24 05:05 ttionya

Same issue here!

I've tried also with the other format but i've received same results!

@ttionya how we can provide you the logs? You refer to the logs showing in console during backup?

This is what i see (i think that dead letter it's my previous attempt to debug)

image

My SMTP ENV:

MAIL_SMTP_ENABLE="TRUE" MAIL_SMTP_VARIABLES=" -S v15-compat -S smtp-use-starttls -S mta=smtp://smtp-relay.gmail.com:587 -S [email protected]" MAIL_TO="[email protected]" MAIL_WHEN_SUCCESS="TRUE" MAIL_WHEN_FAILURE="TRUE"

Thanks a lot!

Capobuf avatar Jun 08 '24 10:06 Capobuf

@Capobuf ,

I'm not sure why this error is occurring. What is the host machine you are using?

ttionya avatar Jun 12 '24 05:06 ttionya

@Capobuf ,

I'm not sure why this error is occurring. What is the host machine you are using?

It's a VMWare VM, with Ubuntu Server 22.04

Capobuf avatar Jun 16 '24 18:06 Capobuf

I got the same error but maybe different issue. I think its problem of parsing the enviroment variable. Writing a little test script I think I figured out a possible fix:

#!/usr/bin/env bash

# Just simulate what sendmail sees
function show_each_arg() {
    for arg in "$@"; do
        echo "[$arg]"
    done
}

# Sample usage, doesnt make sense but just to show there is issue with single quotes
TEST_VAR="-S 'mta=smtp://smtp.gmail.com:587 smtp-use-starttls' -S smtp-use-starttls -S smtp-auth=login"

# THIS IS WHAT WE EXPECT/WANT
show_each_arg -S 'mta=smtp://smtp.gmail.com:587 smtp-use-starttls' -S smtp-use-starttls -S smtp-auth=login
# [-S]
# [mta=smtp://smtp.gmail.com:587 smtp-use-starttls]
# [-S]
# [smtp-use-starttls]
# [-S]
# [smtp-auth=login]


# THIS IS WHAT WE GET
show_each_arg $TEST_VAR
# [-S]
# ['mta=smtp://smtp.gmail.com:587] # <- `mta` is never set! instead `'mta` starting with ' is set 
# [smtp-use-starttls'] # This gets parsed as a positional argument!
# [-S]
# [smtp-use-starttls]
# [-S]
# [smtp-auth=login]


# POSSIBLE FIX
eval "show_each_arg $TEST_VAR"
# [-S]
# [mta=smtp://smtp.gmail.com:587 smtp-use-starttls]
# [-S]
# [smtp-use-starttls]
# [-S]
# [smtp-auth=login]

Fix should be here: https://github.com/ttionya/vaultwarden-backup/blob/d138633929911c564242af13ad75bc8b76b9e8ef/scripts/includes.sh#L107

Maybe

echo "$2" | eval "mail ${MAIL_VERBOSE} -s \"$1\" ${MAIL_SMTP_VARIABLES} \"${MAIL_TO}\""

EDIT: Also want to add this. I think connection refused with 127.0.0.1 means that smtp or mta was not set correctly and is trying to connect to default smtp which is localhost.

Lenart12 avatar Mar 11 '25 19:03 Lenart12

@Lenart12 ,

Thank you for your reply.

If there are spaces after mta= in the configuration, it might cause issues. I don't know the value of your MAIL_SMTP_VARIABLES environment variable, but in the configuration -S v15-compat -S smtp-use-starttls -S mta=smtp://smtp-relay.gmail.com:587 -S [email protected] provided by the user who reported this issue, there are no spaces after mta=. Therefore, I believe this might not be the cause.

If possible, please perform an mail test. This uses the same function calls as during the backup and will display more detailed information when debug mode is enabled. Additionally, I'd like to know your server's connectivity to smtp.gmail.com. You can check this by running the command nslookup smtp.gmail.com and sharing the output. This information will help me troubleshoot and resolve the issue.

Thank you!

ttionya avatar Mar 12 '25 06:03 ttionya

The values I provided were just demonstrational, I have my own mail server. I got my smtp working fine after I removed spaces and quotes from mail variables.

This means I need to use old -S smtp= syntax and cant use -S 'mta= because it requires spaces and also I can't set sender name with -S 'from=Vaultwarden backup <[email protected]>'.

If you want I can make seperate issue for this.

Lenart12 avatar Mar 12 '25 07:03 Lenart12

@Lenart12 , This will indeed cause a problem, I will fix it, please create a new issue for this. Thank you.

ttionya avatar Mar 12 '25 09:03 ttionya