sabre-io / Baikal

Baïkal is a Calendar+Contacts server
https://sabre.io/baikal/
GNU General Public License v3.0
2.52k stars 291 forks source link

Baikal does not send emails to reciepients of shared folders #865

Open gruenie opened 4 years ago

gruenie commented 4 years ago

Baikal version: 0.6.1

Expected behaviour: When I share a calendar in Baikal, the system should send an email to the recipient of the shared calendar including the uri. I think this is a necessary action, because otherwise the reciever would not know the URI of the shared calendar?

Current behaviour: Baikal does not send this email, although I have entered the "Email invite sender address" in the Web-Admin and my php.ini contains all the necessary data of the SMTP-Server. Other Web-Apps on the same server send mails.

Or did I do something wrong?

danastasio commented 4 years ago

I submitted a pull request on the plugin that handles sharing.

https://github.com/sabre-io/dav/pull/1229

gruenie commented 4 years ago

Hi danastasio, thank you for your help and that you pointed me to the right file! ;-) But there are some problems for me with your code:

  1. For me no mail at all has been sent without setting the "from-header". So I added the following lines: if (defined("BAIKAL_INVITE_FROM") && BAIKAL_INVITE_FROM !== "") { $sender = BAIKAL_INVITE_FROM; } else { $sender = "server@baical.loc"; }

And then I added ..., From: '.$Sender); at the end of the mail()-function.

  1. Then the first type of mails has been sent, but the second (revoke) not at all. I was searching for a long time to find the reason. Strange, because the word "Access" in the subject line has been the reason. I changed it to ""Entrance" and the revoke-mails have been sent too. 8-)

  2. I think it is necessary to send the complete link to the person who get access to my calendar and not just the "$path", but I have no idea how to do that.

For example I want to share my default calendar: https://server.tld/dav.php/calendars/myname/default/ to the user "noname", then he needs to get the following link:

https://server.tld/dav.php/calendars/noname/xxx-yyy-zzz/, where "xxx-yyy-zzz" is the uri which you can find in the table calenderinstances/uri, where the calendarid is the one from "principals/myname".

How can we do that? 8-)

danastasio commented 4 years ago

Hi Gruenie,

That's a little curious. Headers are optional in mail() so it's a little weird that you didn't get any mail without them. But if it works for you I'll do some testing and we can probably leave it in there.

Are you using a localization? The type of email that goes out depends on the value of the access dropdown, I can't really see how the subject would affect this but I'll look further into this.

I'm not sure I agree that the end user needs the entire URI. You should be able to give them https://server.tld/baikal/html/dav.php and they will get a list of calendars that they have access to. That's how I do it. Besides that, I'm not really sure how I can get that information out of this file lol. Maybe we could define it in config.php.

gruenie commented 4 years ago

Hi danastasio, thank you for the answer. To the several points: 1. mail(): I also thought that headers are optional in the php-mail()-function. But maybe its not a problem of the php-function because the error-message comes from Baikal/Sabre. When I cancel the from-header I get the following error-message: <d:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns"> <s:sabredav-version>4.0.2</s:sabredav-version> <s:exception>ErrorException</s:exception> <s:message>mail(): Bad Message Return Path</s:message> </d:error> Under php in windows the return-path is identical with the from-header, if not specified seperately.

2. Subject "access" I also had no idea what could be the reason, that the revocation mails did not arrive. Its clear, that the option-value of the access-field is important which type of mails goes out. And I also did not see any errors in your code. Now I found the reason and I have to admit that it is embarassing! :-/ The revoking-mails were filtered out in my mail-account because of the word "access". My goodness! So you can forget this point. Sorry.

3. About the link You are right in general. I also see all shared calendars for example in DAVdroid (DAVx5). But in Thunderbird you have to add every (shared) calendar seperately and there you need the completely url. Look into the table calenderinstances. You need the value in the field "uri" to enter the correct url in thunderbird, f.e. like this: https://server.tld/dav.php/calendars/Username/xxxxxxxx-yyyy-zzzz-xxxx-yyyyyyyyyyyy/. So we would need the information out of the database. I also have no idea how to do that in our case.

danastasio commented 4 years ago
  1. mail() Well if it works for some people without the header, but works for everyone with the headers, it's probably just easier to leave it in there. I'll change the code this weekend to reflect that.

  2. Subject I hate when that happens! Glad it was an easy fix!

  3. The Link I don't use thunderbird so this was new to me. We can get the URI (/baikal/html/dav.php[CALENDAR_NAME]) but it doesn't look like the server address is defined anywhere.

We can probably just define this in config.system.php but that would require changing the install page slightly so the admin sets this up. Then we can call it whenever we want, and send the full URL to the user being shared with. I'll also add a note on the actual sharing page that in order to get a properly formatted link, the server instance must be defined on the settings page.

I wont have time to do this until the weekend, but I think it's doable!

gruenie commented 4 years ago

Hi danastasio, sorry for the late reply. 1. mail(): As I told you, for me the error-message comes from Baikal/Sabre and not from PHP. Maybe it is a difference if the installation runs on Windows or Linux, mine is on a Windows-server. In the new admin-interface you have the ability to set a sender-mail-address if you want to send notifications. If it is empty, no notifications are sent, otherweise yes (value is a constant: BAIKAL_INVITE_FROM). So we should use this option and this value to send or not to send the notifications.

2. Subject "access" Sorry again. ;-)

3. The calendar-link As I said. When I use DAVdroid (new name is DAVx5), then I see in my account all calendars (my own and the calendars which other people invited me to). There I can choose, which should be shown. In Thunderbird (in te AddOn "Lightning") it is sadly completely different. There you need to add every calendar seperately (your own and others) by entering the completely url. Thats not very nice, but at the moment it is like this. since Thunderbird is a really popular mail-client (for Windows and Linux), there should be a soltion too.

It is not the link that you wrote what we need to send in the mail, the link is: https://server.tld/dav.php/calendars/Username/xxxxxxxx-yyyy-zzzz-xxxx-yyyyyyyyyyyy/, where: https://server.tld/dav.php/calendars/ - is the URL of the server to the calendars Username - is the username of the receiver of the invitation (not the name of the sender) xxxxxxxx-yyyy-zzzz-xxxx-yyyyyyyyyyyy - is the value, which you can find in the field uri in the table "calenderinstances".

I have no idea if the server-address is defined anywhere. Maybe it is possible to get it from a $_SERVER-constant or what ever - otherwise it would be necessary to define it in a config-file. More complicated will be to get the URI (calender-ID) from the database.

ByteHamster commented 4 years ago
  1. mail(): As I told you, for me the error-message comes from Baikal/Sabre and not from PHP.

The error message is displayed by sabre/dav but it originates from PHP. The error message means that your SMTP server does not accept the email. Apparently, this is related to the fact that you are not using authenticated SMTP. Unfortunately, php's mail() function does not support authentication on Windows.

  1. The calendar-link

This should be discussed in the pull request on sabre/dav as it is not directly related to Baikal.

gruenie commented 4 years ago

@ ByteHamster: Thank you for your comment and explanation.

  1. mail() Should it nevertheless not be a good idea to add a from-header in the mail-function by default, especially since there is now a possibility to add a sent-mail-address ("BAIKAL_INVITE_FROM") in the admin-interface? I did it in my installation this way: https://github.com/sabre-io/Baikal/issues/865#issuecomment-578322725

  2. The calendar-link Ok, we will continue this discussion in the other topic.