caronc / apprise

Apprise - Push Notifications that work with just about every platform!
https://hub.docker.com/r/caronc/apprise
BSD 2-Clause "Simplified" License
11.71k stars 410 forks source link

Configuring custom E-Mail notifications #990

Closed Salvoxia closed 11 months ago

Salvoxia commented 11 months ago

:question: Question

Hi,

I'm having trouble setting up custom email notifications with Apprise v1.6.0 running in a Docker container.

My mail server expects the full email address as user name, so I have to specify the user in the URL with the user parameter. My SMTP server also has a different host name than my domain, so I need to override that with the smtp parameter. I also want to use implicit SSL on port 465, so I specify the port and mode as well. My full URL looks like this: mailtos://mydomain.com?smtp=mail.local.mydomain.com&user=noreply@mydomain.com&pass=mypassword&from=noreply@mydomain.com&to=me@mydomain.com&mode=ssl&port=465

This is the debug output

apprise -vvvvv -t "test title" -b "test body" mailtos://mydomain.com?smtp=mail.local.mydomain.com&user=noreply@mydomain.com&pass=mypassword&from=noreply@mydomain.com&to=me@mydomain.com&mode=ssl&port=465
[1] 278
[2] 279
[3] 280
[4] 281
[5] 282
[6] 283
[4]   Done                    from=noreply@mydomain.com
www-data@e80a178dc02e:/opt/apprise$ 2023-11-03 17:48:07,457 - TRACE - Loaded language en
2023-11-03 17:48:07,457 - DEBUG - Language set to en
2023-11-03 17:48:07,459 - TRACE - E-Mail URL mailtos://mydomain.com?smtp=mail.local.mydomain.com unpacked as:
user="None"
password="None"
port="None"
host="mydomain.com"
fullpath="None"
path="None"
query="None"
schema="mailtos"
url="mailtos://mydomain.com"
qsd="{'smtp': 'mail.local.mydomain.com'}"
qsd+="{}"
qsd-="{}"
qsd:="{}"
secure="True"
verify="True"
targets="[]"
from_addr=""
smtp_host="mail.local.mydomain.com"
headers="{}"
2023-11-03 17:48:07,460 - WARNING - Invalid ~From~ email specified: 
2023-11-03 17:48:07,460 - ERROR - Could not load E-Mail URL: mailtos://mydomain.com?smtp=m...e
2023-11-03 17:48:07,460 - ERROR - There are no service(s) to notify

[1]   Exit 1                  apprise -vvvvv -t "test title" -b "test body" mailtos://mydomain.com?smtp=mail.local.mydomain.com
[2]   Done                    user=noreply@mydomain.com
[3]   Done                    pass=mypassword
[5]-  Done                    to=me@mydomain.com
[6]+  Done                    mode=ssl

Using this URL Apprise complains about missing "from" address, but it's clearly specified using the from parameter in the URL.

So I tried a different variation with the password@domain notation, specifying only the user in the URL with the user parameter: mailtos://mypassword@mydomain.com?smtp=mail.local.mydomain.com&user=noreply@mydomain.com&from=noreply@mydomain.com&to=me@mydomain.com&mode=ssl&port=465

Debug output:

apprise -vvvvv -t "test title" -b "test body" mailtos://mypassword@mydomain.com?smtp=mail.local.mydomain.com&user=noreply@mydomain.com&from=noreply@mydomain.com&to=me@mydomain.com&mode=ssl&port=465
[1] 261
[2] 262
[3] 263
[4] 264
[5] 265
www-data@e80a178dc02e:/opt/apprise$ 2023-11-03 17:40:01,050 - TRACE - Loaded language en
2023-11-03 17:40:01,050 - DEBUG - Language set to en
2023-11-03 17:40:01,052 - TRACE - E-Mail URL mailtos://mypassword@mydomain.com?smtp=mail.local.mydomain.com unpacked as:
user="mypassword"
password="None"
port="None"
host="mydomain.com"
fullpath="None"
path="None"
query="None"
schema="mailtos"
url="mailtos://mypassword@mydomain.com"
qsd="{'smtp': 'mail.local.mydomain.com'}"
qsd+="{}"
qsd-="{}"
qsd:="{}"
secure="True"
verify="True"
targets="[]"
from_addr=""
smtp_host="mail.local.mydomain.com"
headers="{}"
2023-11-03 17:40:01,053 - DEBUG - Loaded E-Mail URL: mailtos://mypassword@mydomain.com/?format=html&overflow=upstream&rto=4.0&cto=15&verify=yes&smtp=mail.local.mydomain.com&mode=starttls
2023-11-03 17:40:01,053 - DEBUG - Email From: Apprise <mypassword@mydomain.com>
2023-11-03 17:40:01,053 - DEBUG - Email To: mypassword@mydomain.com
2023-11-03 17:40:01,053 - DEBUG - Login ID: mypassword
2023-11-03 17:40:01,053 - DEBUG - Delivery: mail.local.mydomain.com:587
2023-11-03 17:40:01,054 - DEBUG - Connecting to remote SMTP server...
2023-11-03 17:40:01,057 - WARNING - Connection error while submitting email to mail.local.mydomain.com. Reason: [Errno 111] Connection refused

[1]   Exit 1                  apprise -vvvvv -t "test title" -b "test body" mailtos://mypassword@mydomain.com?smtp=mail.local.mydomain.com
[2]   Done                    user=noreply@mydomain.com
[3]   Done                    from=noreply@mydomain.com
[4]-  Done                    to=me@mydomain.com
[5]+  Done                    mode=ssl

Now it uses my password as user to build the from and to address, ignoring both from and to parameters, also ignoring the port parameter specifying 465.

So now I tried moving both username and password to URL parameters like in my first try, but now the order of the parameters is different: mailtos://mydomain.com?user=noreply@mydomain.com&pass=mypassword&smtp=mail.local.mydomain.com&from=noreply@mydomain.com&to=me@mydomain.com&mode=ssl&port=465

Debug output:

apprise -vvvvv -t "test title" -b "test body" mailtos://mydomain.com?user=noreply@mydomain.com&pass=mypassword&smtp=mail.local.mydomain.com&from=noreply@mydomain.com&to=me@mydomain.com&mode=ssl&port=465
[1] 272
[2] 273
[3] 274
[4] 275
[5] 276
[6] 277
www-data@e80a178dc02e:/opt/apprise$ 2023-11-03 17:45:47,263 - TRACE - Loaded language en
2023-11-03 17:45:47,263 - DEBUG - Language set to en
2023-11-03 17:45:47,267 - TRACE - E-Mail URL mailtos://mydomain.com?user=noreply@mydomain.com unpacked as:
user="noreply@mydomain.com"
password="None"
port="None"
host="mydomain.com"
fullpath="None"
path="None"
query="None"
schema="mailtos"
url="mailtos://mydomain.com"
qsd="{'user': 'noreply@mydomain.com'}"
qsd+="{}"
qsd-="{}"
qsd:="{}"
secure="True"
verify="True"
targets="[]"
from_addr=""
smtp_host=""
headers="{}"
2023-11-03 17:45:47,268 - TRACE - Scanning noreply@mydomain.com against Google Mail
2023-11-03 17:45:47,268 - TRACE - Scanning noreply@mydomain.com against Yandex
2023-11-03 17:45:47,268 - TRACE - Scanning noreply@mydomain.com against Microsoft Hotmail
2023-11-03 17:45:47,268 - TRACE - Scanning noreply@mydomain.com against Microsoft Outlook
2023-11-03 17:45:47,268 - TRACE - Scanning noreply@mydomain.com against Microsoft Office 365
2023-11-03 17:45:47,268 - TRACE - Scanning noreply@mydomain.com against Yahoo Mail
2023-11-03 17:45:47,268 - TRACE - Scanning noreply@mydomain.com against Fast Mail
2023-11-03 17:45:47,268 - TRACE - Scanning noreply@mydomain.com against Fast Mail Extended Addresses
2023-11-03 17:45:47,268 - TRACE - Scanning noreply@mydomain.com against Zoho Mail
2023-11-03 17:45:47,268 - TRACE - Scanning noreply@mydomain.com against SendGrid
2023-11-03 17:45:47,268 - TRACE - Scanning noreply@mydomain.com against 163.com
2023-11-03 17:45:47,268 - TRACE - Scanning noreply@mydomain.com against Foxmail.com
2023-11-03 17:45:47,268 - TRACE - Scanning noreply@mydomain.com against Custom
2023-11-03 17:45:47,268 - INFO - Applying Custom Defaults
2023-11-03 17:45:47,268 - DEBUG - Loaded E-Mail URL: mailtos://noreply@mydomain.com/?format=html&overflow=upstream&rto=4.0&cto=15&verify=yes&mode=starttls
2023-11-03 17:45:47,269 - DEBUG - Email From: Apprise <noreply@mydomain.com>
2023-11-03 17:45:47,269 - DEBUG - Email To: noreply@mydomain.com
2023-11-03 17:45:47,269 - DEBUG - Login ID: noreply@mydomain.com
2023-11-03 17:45:47,269 - DEBUG - Delivery: mydomain.com:587
2023-11-03 17:45:47,270 - DEBUG - Connecting to remote SMTP server...
2023-11-03 17:45:47,272 - WARNING - Connection error while submitting email to mydomain.com. Reason: [Errno 111] Connection refused

[1]   Exit 1                  apprise -vvvvv -t "test title" -b "test body" mailtos://mydomain.com?user=noreply@mydomain.com
[2]   Done                    pass=mypassword
[3]   Done                    smtp=mail.local.mydomain.com
[4]   Done                    from=noreply@mydomain.com
[5]-  Done                    to=me@mydomain.com
[6]+  Done                    mode=ssl

This time it again ignores my to URL parameter, as well as smtpand port, so the order in which the parameters are specified in the URL matters...?

I have no clue what I'm doing wrong and I'm very confused. Any help is much appreciated!

Best Regards, Salvoxia

caronc commented 11 months ago

This is definitely something I'll need to investigate further. I can't spot anything unusual off hand. This weekend I'll try to reproduce it as you've given me great examples to work with!🙂

caronc commented 11 months ago

I tested your configuration and it works perfectly. Not sure why i didn't notice this upfront, but i spotted it now.

apprise -vvvvv -t "test title" -b "test body" mailtos://mydomain.com?smtp=mail.local.mydomain.com&user=noreply@mydomain.com&pass=mypassword&from=noreply@mydomain.com&to=me@mydomain.com&mode=ssl&port=465
[1] 278
[2] 279
[3] 280
[4] 281
[5] 282
[6] 283

You see the [1], [2], etc... ?

This is because & is interpreted by the Linux/Bash Interpreter to launch the content into the background. Wrap quotes ("maitos://credentials") around your URL and it will probably work perfectly for you.

apprise -vvvvv -t "test title" -b "test body" \
   "mailtos://mydomain.com?smtp=mail.local.mydomain.com&user=noreply@mydomain.com&pass=mypassword&from=noreply@mydomain.com&to=me@mydomain.com&mode=ssl&port=465"
Salvoxia commented 11 months ago

Well, now I feel really dumb. Tested with the quotes and of course you are right, it works just as expected! Thank you for your time and effort!