messages
feishu.mail.messages
¶
MessagesNamespace
¶
Bases: Namespace
用户邮箱邮件命名空间。
通过 client.mail.messages 访问,封装用户邮箱邮件列表、详情、发送、邮件卡片解析与批量修改接口。
复杂 MIME 构造由调用方负责;本命名空间仅按飞书 mail/v1 的请求体字段做薄封装。
飞书文档
源代码位于: feishu/mail/messages.py
| Python | |
|---|---|
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | |
batch_modify
async
¶
batch_modify(user_mailbox_id: str, *, message_ids: Sequence[str] | None = None, add_label_ids: Sequence[str] | None = None, remove_label_ids: Sequence[str] | None = None, add_folder: str | None = None) -> NestedDict
批量修改邮件标签、所属文件夹或已读未读状态。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
|
str
|
用户邮箱地址,或用户态调用时的 |
必需 |
|
Sequence[str] | None
|
需要修改的邮件 ID 列表。 |
None
|
|
Sequence[str] | None
|
待添加的标签 ID 列表。 |
None
|
|
Sequence[str] | None
|
待移除的标签 ID 列表。 |
None
|
|
str | None
|
需要移入的文件夹 ID。 |
None
|
返回:
| 类型 | 描述 |
|---|---|
NestedDict
|
飞书返回的 |
引发:
| 类型 | 描述 |
|---|---|
FeishuError
|
请求失败或返回错误码时抛出。 |
飞书文档
示例:
| Python Console Session | |
|---|---|
源代码位于: feishu/mail/messages.py
get
async
¶
get(user_mailbox_id: str, message_id: str, *, format: str | None = None) -> NestedDict
获取邮件详情。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
|
str
|
用户邮箱地址,或用户态调用时的 |
必需 |
|
str
|
邮件 ID。 |
必需 |
|
str | None
|
返回内容格式,飞书支持 |
None
|
返回:
| 类型 | 描述 |
|---|---|
NestedDict
|
飞书返回的 |
引发:
| 类型 | 描述 |
|---|---|
FeishuError
|
请求失败或返回错误码时抛出。 |
飞书文档
示例:
| Python Console Session | |
|---|---|
源代码位于: feishu/mail/messages.py
get_by_card
async
¶
get_by_card(user_mailbox_id: str, *, card_id: str, owner_id: str, user_id_type: str = 'open_id') -> NestedDict
获取邮件卡片下的邮件列表。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
|
str
|
用户邮箱地址,或用户态调用时的 |
必需 |
|
str
|
邮件卡片 ID。 |
必需 |
|
str
|
邮件卡片 Owner ID。 |
必需 |
|
str
|
Owner ID 类型,默认 |
'open_id'
|
返回:
| 类型 | 描述 |
|---|---|
NestedDict
|
飞书返回的 |
引发:
| 类型 | 描述 |
|---|---|
FeishuError
|
请求失败或返回错误码时抛出。 |
飞书文档
示例:
| Python Console Session | |
|---|---|
源代码位于: feishu/mail/messages.py
list
async
¶
list(user_mailbox_id: str, *, page_size: int = MAIL_MESSAGE_PAGE_SIZE_MAX, max_items: int | None = None, folder_id: str | None = None, only_unread: bool | None = None, label_id: str | None = None) -> list[str]
列出用户邮箱中的邮件 ID。
自动翻页并将各页邮件 ID 拼接为单个列表返回。飞书该接口每页上限为 20,page_size
大于 20 时会在客户端侧收敛。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
|
str
|
用户邮箱地址,或用户态调用时的 |
必需 |
|
int
|
每页数量,默认 20。 |
MAIL_MESSAGE_PAGE_SIZE_MAX
|
|
int | None
|
最多返回的邮件 ID 数量;为空表示返回全部。 |
None
|
|
str | None
|
文件夹 ID,例如 |
None
|
|
bool | None
|
是否只查询未读邮件。 |
None
|
|
str | None
|
标签 ID,例如 |
None
|
返回:
| 类型 | 描述 |
|---|---|
list[str]
|
邮件 ID 列表。 |
引发:
| 类型 | 描述 |
|---|---|
FeishuError
|
请求失败或返回错误码时抛出。 |
飞书文档
示例:
| Python Console Session | |
|---|---|
源代码位于: feishu/mail/messages.py
search
async
¶
search(user_mailbox_id: str, *, query: str | None = None, filter: dict[str, Any] | None = None, page_size: int = MAIL_SEARCH_PAGE_SIZE_MAX, max_items: int | None = None) -> list[NestedDict]
搜索用户当前账户下的邮件。
自动翻页并将各页搜索结果拼接为单个列表返回。飞书该接口仅支持 user_access_token,
调用方通常应使用 client.as_user(user_token).mail.messages.search(...)。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
|
str
|
用户邮箱地址,或用户态调用时的 |
必需 |
|
str | None
|
搜索关键词;为空时省略。 |
None
|
|
dict[str, Any] | None
|
搜索过滤条件,原样传给飞书,如 |
None
|
|
int
|
每页数量,默认 15;超过飞书上限时按 15 收敛。 |
MAIL_SEARCH_PAGE_SIZE_MAX
|
|
int | None
|
最多返回的搜索结果数量;为空表示返回全部。 |
None
|
返回:
| 类型 | 描述 |
|---|---|
list[NestedDict]
|
搜索结果列表,每项包含 |
引发:
| 类型 | 描述 |
|---|---|
FeishuError
|
请求失败或返回错误码时抛出。 |
飞书文档
示例:
| Python Console Session | |
|---|---|
源代码位于: feishu/mail/messages.py
send
async
¶
send(user_mailbox_id: str, *, subject: str | None = None, to: Sequence[dict[str, Any]] | None = None, raw: str | None = None, cc: Sequence[dict[str, Any]] | None = None, bcc: Sequence[dict[str, Any]] | None = None, body_html: str | None = None, body_plain_text: str | None = None, attachments: Sequence[dict[str, Any]] | None = None, dedupe_key: str | None = None, head_from: dict[str, Any] | None = None, **opts: Any) -> NestedDict
发送邮件。
飞书发送接口通常需要用户身份调用;可使用 client.as_user(user_token).mail.messages.send(...)。
raw 与附件正文均应由调用方按飞书文档提供 base64url 编码内容。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
|
str
|
用户邮箱地址,或用户态调用时的 |
必需 |
|
str | None
|
邮件主题。 |
None
|
|
Sequence[dict[str, Any]] | None
|
收件人列表,每项形如 |
None
|
|
str | None
|
base64url 编码后的 EML 数据。 |
None
|
|
Sequence[dict[str, Any]] | None
|
抄送人列表。 |
None
|
|
Sequence[dict[str, Any]] | None
|
密送人列表。 |
None
|
|
str | None
|
HTML 正文。 |
None
|
|
str | None
|
纯文本正文。 |
None
|
|
Sequence[dict[str, Any]] | None
|
附件列表。 |
None
|
|
str | None
|
去重键。 |
None
|
|
dict[str, Any] | None
|
EML 中发件人信息。 |
None
|
|
Any
|
其他飞书支持的请求体字段;值为 |
{}
|
返回:
| 类型 | 描述 |
|---|---|
NestedDict
|
飞书返回的 |
引发:
| 类型 | 描述 |
|---|---|
FeishuError
|
请求失败或返回错误码时抛出。 |
飞书文档
示例:
| Python Console Session | |
|---|---|