# Use API to get mail address for given username

**URL:** https://meta.discourse.org/t/use-api-to-get-mail-address-for-given-username/47872
**Category:** Support
**Created:** [2016年七月27日 17:17 UTC](https://meta.discourse.org/t/use-api-to-get-mail-address-for-given-username/47872 "2016-07-27T17:17:06Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![rriemann](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rriemann/32/115238_2.png) [@rriemann](https://meta.discourse.org/u/rriemann)
#### Post date: [2016年七月27日 17:17 UTC](https://meta.discourse.org/t/use-api-to-get-mail-address-for-given-username/47872/1 "2016-07-27T17:17:06Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [2016年七月27日 17:39 UTC](https://meta.discourse.org/t/use-api-to-get-mail-address-for-given-username/47872/2 "2016-07-27T17:39:29Z")

</div>

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

---

<div class="post-metadata">

### Author: ![rriemann](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rriemann/32/115238_2.png) [@rriemann](https://meta.discourse.org/u/rriemann)
#### Post date: [2016年七月27日 17:51 UTC](https://meta.discourse.org/t/use-api-to-get-mail-address-for-given-username/47872/3 "2016-07-27T17:51:03Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [2016年七月27日 17:52 UTC](https://meta.discourse.org/t/use-api-to-get-mail-address-for-given-username/47872/4 "2016-07-27T17:52:52Z")

</div>

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

---

<div class="post-metadata">

### Author: ![rriemann](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rriemann/32/115238_2.png) [@rriemann](https://meta.discourse.org/u/rriemann)
#### Post date: [2016年七月27日 17:55 UTC](https://meta.discourse.org/t/use-api-to-get-mail-address-for-given-username/47872/5 "2016-07-27T17:55:15Z")

</div>

I was studying the file [discourse/config/routes.rb at main · discourse/discourse · GitHub](https://github.com/discourse/discourse/blob/master/config/routes.rb) but did not realised that it was `PUT`. Now it works. 🙂

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [2016年七月27日 18:15 UTC](https://meta.discourse.org/t/use-api-to-get-mail-address-for-given-username/47872/6 "2016-07-27T18:15:58Z")

</div>

There you go 🌾

[https://github.com/discourse/discourse/commit/c4b52b1a19e7cacdcd84989bd9309b6d35df9e55](https://github.com/discourse/discourse/commit/c4b52b1a19e7cacdcd84989bd9309b6d35df9e55)

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [2016年七月27日 18:16 UTC](https://meta.discourse.org/t/use-api-to-get-mail-address-for-given-username/47872/7 "2016-07-27T18:16:01Z")

</div>



---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [2016年七月31日 19:53 UTC](https://meta.discourse.org/t/use-api-to-get-mail-address-for-given-username/47872/8 "2016-07-31T19:53:19Z")

</div>

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.
