Use API to get mail address for given username

AI-generated summary

rriemann is trying to create a script that routes incoming emails to association members’ private mail accounts by reusing their approved forum mail addresses. They can’t find the mail address in the forum API data and ask for help. zogstrip suggests using the PUT /users/<username>/emails.json route, which initially doesn’t work due to a verb issue. After zogstrip edits their post to note the verb issue, rriemann studies the routes file and gets it working. zogstrip commits a fix for the verb issue. riking explains that the non-GET request is used to trigger a staff action log.

Hello,

I want to hack a script that routes incoming mails @association.org from the server to the private mail accounts of the association members. I assume that all members have a forum account and want to reuse the already approved mail address from the forum db.

I checked the data that is returned from the forum API for a given username, but I cannot find the mail address. How do I get it?

Have you tried to PUT /users/<username>/emails.json?

I tried and I just get a html page saying content would not exist or is private. I used the api key generated for all users and the api_user system or the username of my admin account.

I edited my previous post. This route uses the PUT verb but shouldn’t :frowning: Will fix.

I was studying the file discourse/config/routes.rb at main · discourse/discourse · GitHub but did not realised that it was PUT. Now it works. :slight_smile:

There you go :ear_of_rice:

https://github.com/discourse/discourse/commit/c4b52b1a19e7cacdcd84989bd9309b6d35df9e55

The point of that being non-GET is that it causes a staff action log, so it shouldn’t be triggereable from an img or an idempotent request retry thing.