# 电子邮件的 REST API 端点

使用 REST API 管理经过身份验证的用户的电子邮件地址。

## 关于电子邮件管理

如果请求 URL 不包含 `{username}` 参数，则响应将针对已登录的用户（并且必须使用请求传递 [身份验证信息](/zh/enterprise-server@3.22/rest/authentication/authenticating-to-the-rest-api)）。 在通过 基本身份验证或作用域为 `user` 的 OAuth 进行身份验证时，将包含其他专用信息，例如用户是否启用双重身份验证。

> \[!NOTE]
> Most endpoints use `Authorization: Bearer <YOUR-TOKEN>` and `Accept: application/vnd.github+json` headers, plus `X-GitHub-Api-Version: 2026-03-10`. Curl examples below omit these standard headers for brevity.

## List email addresses for the authenticated user

```
GET /user/emails
```

Lists all of your email addresses, and specifies which one is visible
to the public.
OAuth app tokens and personal access tokens (classic) need the user:email scope to use this endpoint.

### Parameters

#### Headers

* **`accept`** (string)
  Setting to `application/vnd.github+json` is recommended.

#### Path and query parameters

* **`per_page`** (integer)
  The number of results per page (max 100). For more information, see "Using pagination in the REST API."
  Default: `30`

* **`page`** (integer)
  The page number of the results to fetch. For more information, see "Using pagination in the REST API."
  Default: `1`

### HTTP response status codes

* **200** - OK

* **304** - Not modified

* **401** - Requires authentication

* **403** - Forbidden

* **404** - Resource not found

### Code examples

#### Example

**Request:**

```curl
curl -L \
  -X GET \
  http(s)://HOSTNAME/api/v3/user/emails
```

**Response schema (Status: 200):**

Array of `Email`:

* `email`: required, string, format: email
* `primary`: required, boolean
* `verified`: required, boolean
* `visibility`: required, string or null

## Add an email address for the authenticated user

```
POST /user/emails
```

OAuth app tokens and personal access tokens (classic) need the user scope to use this endpoint.

### Parameters

#### Headers

* **`accept`** (string)
  Setting to `application/vnd.github+json` is recommended.

#### Body parameters

* **`emails`** (array of strings) (required)
  Adds one or more email addresses to your GitHub account. Must contain at least one email address. Note: Alternatively, you can pass a single email address or an array of emails addresses directly, but we recommend that you pass an object using the emails key.

### HTTP response status codes

* **201** - Created

* **304** - Not modified

* **401** - Requires authentication

* **403** - Forbidden

* **404** - Resource not found

* **422** - Validation failed, or the endpoint has been spammed.

### Code examples

#### Example adding multiple email addresses

**Request:**

```curl
curl -L \
  -X POST \
  http(s)://HOSTNAME/api/v3/user/emails \
  -d '{
  "emails": [
    "octocat@github.com",
    "mona@github.com",
    "octocat@octocat.org"
  ]
}'
```

**Response schema (Status: 201):**

Same response schema as [List email addresses for the authenticated user](#list-email-addresses-for-the-authenticated-user).

## Delete an email address for the authenticated user

```
DELETE /user/emails
```

OAuth app tokens and personal access tokens (classic) need the user scope to use this endpoint.

### Parameters

#### Headers

* **`accept`** (string)
  Setting to `application/vnd.github+json` is recommended.

#### Body parameters

* **`emails`** (array of strings) (required)
  Email addresses associated with the GitHub user account.

### HTTP response status codes

* **204** - No Content

* **304** - Not modified

* **401** - Requires authentication

* **403** - Forbidden

* **404** - Resource not found

* **422** - Validation failed, or the endpoint has been spammed.

### Code examples

#### Example deleting multiple email accounts

**Request:**

```curl
curl -L \
  -X DELETE \
  http(s)://HOSTNAME/api/v3/user/emails \
  -d '{
  "emails": [
    "octocat@github.com",
    "mona@github.com"
  ]
}'
```

**Response schema (Status: 204):**

## List public email addresses for the authenticated user

```
GET /user/public_emails
```

Lists your publicly visible email address, which you can set with the
Set primary email visibility for the authenticated user
endpoint.
OAuth app tokens and personal access tokens (classic) need the user:email scope to use this endpoint.

### Parameters

#### Headers

* **`accept`** (string)
  Setting to `application/vnd.github+json` is recommended.

#### Path and query parameters

* **`per_page`** (integer)
  The number of results per page (max 100). For more information, see "Using pagination in the REST API."
  Default: `30`

* **`page`** (integer)
  The page number of the results to fetch. For more information, see "Using pagination in the REST API."
  Default: `1`

### HTTP response status codes

* **200** - OK

* **304** - Not modified

* **401** - Requires authentication

* **403** - Forbidden

* **404** - Resource not found

### Code examples

#### Example

**Request:**

```curl
curl -L \
  -X GET \
  http(s)://HOSTNAME/api/v3/user/public_emails
```

**Response schema (Status: 200):**

Same response schema as [List email addresses for the authenticated user](#list-email-addresses-for-the-authenticated-user).