watchtower icon indicating copy to clipboard operation
watchtower copied to clipboard

Quoted env variables don't work when containing comma

Open ehaehner opened this issue 1 year ago • 5 comments

Describe the bug

Hi. I want to set multiple recipients for email notifications. PR #436 should have included this but it seems that the commit linked below removed it again.

https://github.com/containrrr/watchtower/commit/35490c853d95f9ead6799bd2a16c991a0e1a0ddf#diff-bd0b1fd9ac0e1afadce1d756b31f0160ff2f61a788a085316599fd7997721bb4

Is it possible to reinclude this feature?

Steps to reproduce

  1. Set "WATCHTOWER_NOTIFICATION_EMAIL_TO" to "[email protected],[email protected]" (multiple mail addresses)
  2. start watchtower
  3. Error: "Failed to send shoutrrr notification" error="error sending message to recipient: error setting RCPT: 501 5.1.3 Bad recipient address syntax" index=0 notify=no service=smtp

Expected behavior

notification is send to all configured email addresses

Screenshots

No response

Environment

  • Platform: Debian Bookworm
  • Docker Version: 24.0.7

Your logs

level=error msg="Failed to send shoutrrr notification" error="error sending message to recipient: error setting RCPT: 501 5.1.3 Bad recipient address syntax" index=0 notify=no service=smtp

Additional context

No response

ehaehner avatar Jan 06 '24 14:01 ehaehner

Hi there! 👋🏼 As you're new to this repo, we'd like to suggest that you read our code of conduct as well as our contribution guidelines. Thanks a bunch for opening your first issue! 🙏

github-actions[bot] avatar Jan 06 '24 14:01 github-actions[bot]

Multiple recipients should work fine for shoutrrr. It might be something with the legacy notifications adapter that encodes the commas, perhaps?

Try using a shoutrrr URL directly instead:

WATCHTOWER_NOTIFICATION_URL: smtp://username:password@host:port/?from=fromAddress&to=recipient1,recipient2

(you can see what the adapter transforms your notification configuration to if you run watchtower with --trace)

piksel avatar Jan 07 '24 00:01 piksel

Setting this environment variable fixed the issue so I could find the issue on my side.

I used the following compose notation:

version: "3"
services:
  watchtower:
    environment:
      - WATCHTOWER_MONITOR_ONLY=true
      - WATCHTOWER_NOTIFICATIONS=email
      - WATCHTOWER_NOTIFICATIONS_LEVEL=info
      - WATCHTOWER_NO_STARTUP_MESSAGE=true
      - WATCHTOWER_NOTIFICATION_EMAIL_SERVER=mail
      - WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PORT=25
      - WATCHTOWER_NOTIFICATION_EMAIL_DELAY=2
      - WATCHTOWER_NOTIFICATION_EMAIL_SERVER_TLS_SKIP_VERIFY=true
      - WATCHTOWER_NOTIFICATION_EMAIL_FROM="[email protected]"
      - WATCHTOWER_NOTIFICATION_EMAIL_TO="[email protected],[email protected]"
      - WATCHTOWER_LOG_LEVEL=trace
[...]

Removing the quotes fixed the issue. Quotes are fine for one recipient but with a comma the mentioned error is printed. Thank you for the support @piksel

ehaehner avatar Jan 07 '24 12:01 ehaehner

Interesting! So this was caused by docker compose's environment parsing... Or perhaps it's due to our attempts at cleaning extra quotes that split the input into addresses before removing quotes...

I'll reopen this until it's properly investigated.

piksel avatar Jan 08 '24 09:01 piksel

I just want to add another thing. This behavior seems to depend on the compose notation. I switched environment definition from a list to a map and then it is possible to use quotes.

The following two definitions are working:

ehaehner avatar Jan 08 '24 19:01 ehaehner