0

Send mail

by
Published Oct 17, 2025
Script zoho Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Zoho = {
3
  token: string;
4
};
5
/**
6
 * Send mail
7
 *
8
 */
9
export async function main(
10
  auth: Zoho,
11
  moduleName: string,
12
  id: string,
13
  body: {
14
    data: {
15
      from: { user_name: string; email: string };
16
      to: { user_name: string; email: string }[];
17
      cc: { user_name: string; email: string }[];
18
      bcc: { user_name: string; email: string }[];
19
      reply_to: { user_name: string; email: string };
20
      org_email: false | true;
21
      scheduled_time: string;
22
      mail_format: "html" | "text";
23
      consent_email: false | true;
24
      content: string;
25
      subject: string;
26
      in_reply_to: {
27
        message_id?: string;
28
        owner?: { id?: string; name?: string };
29
      };
30
      template:
31
        | {
32
            attachments: {
33
              size?: number;
34
              file_name?: string;
35
              file_id?: string;
36
              id?: string;
37
            }[];
38
            subject: string;
39
            associated: false | true;
40
            consent_linked: false | true;
41
            description?: string;
42
            last_version_statistics: {
43
              tracked: number;
44
              delivered: number;
45
              opened: number;
46
              bounced: number;
47
              sent: number;
48
              clicked: number;
49
            };
50
            category?: string;
51
            created_time: string;
52
            modified_time: string;
53
            last_usage_time: string;
54
            folder: { name: string; id: string };
55
            module: { api_name: string; id: string };
56
            created_by: { name: string; id: string };
57
            modified_by: { name: string; id: string };
58
            name: string;
59
            id: string;
60
            editor_mode: string;
61
            favorite: false | true;
62
            content: string;
63
            mail_content: string;
64
          }
65
        | {
66
            created_time: string;
67
            modified_time: string;
68
            last_usage_time: string;
69
            folder: { name: string; id: string };
70
            module: { api_name: string; id: string };
71
            created_by: { name: string; id: string };
72
            modified_by: { name: string; id: string };
73
            name: string;
74
            id: string;
75
            editor_mode: string;
76
            category: string;
77
            favorite: false | true;
78
            content: string;
79
            active: false | true;
80
            mail_content: string;
81
          };
82
      inventory_details: { inventory_template: { id: string; name?: string } };
83
      data_subject_request: { id: string; type: string };
84
      attachments: { id: string }[];
85
      linked_record: {
86
        module: { api_name: string; id: string };
87
        name: string;
88
        id: string;
89
      };
90
    }[];
91
  },
92
) {
93
  const url = new URL(
94
    `https://zohoapis.com/crm/v8/${moduleName}/${id}/actions/send_mail`,
95
  );
96

97
  const response = await fetch(url, {
98
    method: "POST",
99
    headers: {
100
      "Content-Type": "application/json",
101
      Authorization: "Zoho-oauthtoken " + auth.token,
102
    },
103
    body: JSON.stringify(body),
104
  });
105
  if (!response.ok) {
106
    const text = await response.text();
107
    throw new Error(`${response.status} ${text}`);
108
  }
109
  return await response.json();
110
}
111