How to send mails with accept / decline option

Hi, I’ve build my first app with the help of the tutorial and it’s going great.

Now I’d like to send mails to users with the option to accept / decline, which then triggers a method back in the Nextcloud. Anyone knows which methods / classes to include / combine? I’ve looked into the code of the Calendar app that already does that for events, but it was a bit much. Could anyone provide a shortcut answer?

If you are referring to a calendar-like entry, you will have to dig into the calendar, I fear.

When you want to just send out some mails and let the (anonymous) user confirm their mail address, you can register some sort of token (add a due date) for each user and store it in the database. Then, you add a route to your app that either directly validates the token or brings the user to a public site that will use a small Vue app to validate the appointment/issue/…

It is a bit hard o help you without knowing where the problems lie and what you are not understanding/having trouble with. Related to (gerneric) mailing, see IMailer. Public pages as well as Routing might connect all pieces together. Accessing the DB can be found as well.

So, now it is up to you to tell us, what is and what is not working so far.


1 Like

Hi Christian,
thanks so much for the quick reply. Routing does look very promising, I didn’t see the URL generator part there at the bottom.

Regarding what I’m planning to do: I have a “help request” class with id, title (…) and an integer variable for “pending”, “accepted”, “declined”. As users that need to reply to these requests are not constantly logged into the Nextcloud, I thought it would maybe be easy to send mails with two generated urls that then set the integer variable, depending on which button in the e-mail is clicked.

This means that the browser will open any link with GET verb from the server.

So, you must define a link pattern (like e.g. /apps/your-app-name/request/{id}/accept, where {id} is the numerical id). It is up to you how you do this. Keep in mind, what is required and also take security into account.

Then, you can define a route to a public page (user is not logged in) with that pattern. This is described in the routing and public pages section.

The controller will simply trigger the update (accept of a certain id above). After the update, the user is shown some confirmation or redirected wherever.

You can send the mail after creating the help requests when the id is known. Then, the URL is well-defined and you can compose the mail itself.

That should do the trick as far as I see it.

1 Like

Fantastic! That should do the trick, indeed. Somehow I was thinking that I needed something more complex regarding urls, but this solution makes everything a lot easier.


1 Like