0

Reply to Email

by
Published today

Reply to a message (or reply-all) and send it immediately. The comment is placed above the quoted original. 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
 * Reply to Email
5
 * Reply to a message (or reply-all) and send it immediately. The comment is placed above the quoted original. Requires Mail.Send (a connection default).
6
 */
7
export async function main(
8
  auth: RT.Outlook,
9
  message_id: string,
10
  comment: string,
11
  reply_all: boolean = false,
12
  mailbox: string | undefined
13
) {
14
  const base = `https://graph.microsoft.com/v1.0/${
15
    mailbox != null && mailbox !== ""
16
      ? `users/${encodeURIComponent(mailbox)}`
17
      : "me"
18
  }`
19
  const response = await fetch(
20
    `${base}/messages/${encodeURIComponent(message_id)}/${
21
      reply_all ? "replyAll" : "reply"
22
    }`,
23
    {
24
      method: "POST",
25
      headers: {
26
        Authorization: `Bearer ${auth.token}`,
27
        "Content-Type": "application/json",
28
        Accept: "application/json",
29
      },
30
      body: JSON.stringify({ comment }),
31
    }
32
  )
33

34
  if (!response.ok) {
35
    throw new Error(`${response.status} ${await response.text()}`)
36
  }
37

38
  // 202 Accepted with an empty body
39
  return { success: true }
40
}
41