0

Send Draft

by
Published today

Send an existing draft message. Requires Mail.Send (a connection default).

Script outlook Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 5 hours ago
1
//native
2

3
/**
4
 * Send Draft
5
 * Send an existing draft message. Requires Mail.Send (a connection default).
6
 */
7
export async function main(
8
  auth: RT.Outlook,
9
  message_id: string,
10
  mailbox: string | undefined
11
) {
12
  const base = `https://graph.microsoft.com/v1.0/${
13
    mailbox != null && mailbox !== ""
14
      ? `users/${encodeURIComponent(mailbox)}`
15
      : "me"
16
  }`
17
  const response = await fetch(
18
    `${base}/messages/${encodeURIComponent(message_id)}/send`,
19
    {
20
      method: "POST",
21
      headers: {
22
        Authorization: `Bearer ${auth.token}`,
23
        Accept: "application/json",
24
      },
25
    }
26
  )
27

28
  if (!response.ok) {
29
    throw new Error(`${response.status} ${await response.text()}`)
30
  }
31

32
  // 202 Accepted with an empty body
33
  return { success: true }
34
}
35