Edits history of script submission #21928 for ' Send mail (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Send mail
     *
     */
    export async function main(
      auth: Zoho,
      moduleName: string,
      id: string,
      body: {
        data: {
          from: { user_name: string; email: string };
          to: { user_name: string; email: string }[];
          cc: { user_name: string; email: string }[];
          bcc: { user_name: string; email: string }[];
          reply_to: { user_name: string; email: string };
          org_email: false | true;
          scheduled_time: string;
          mail_format: "html" | "text";
          consent_email: false | true;
          content: string;
          subject: string;
          in_reply_to: {
            message_id?: string;
            owner?: { id?: string; name?: string };
          };
          template:
            | {
                attachments: {
                  size?: number;
                  file_name?: string;
                  file_id?: string;
                  id?: string;
                }[];
                subject: string;
                associated: false | true;
                consent_linked: false | true;
                description?: string;
                last_version_statistics: {
                  tracked: number;
                  delivered: number;
                  opened: number;
                  bounced: number;
                  sent: number;
                  clicked: number;
                };
                category?: string;
                created_time: string;
                modified_time: string;
                last_usage_time: string;
                folder: { name: string; id: string };
                module: { api_name: string; id: string };
                created_by: { name: string; id: string };
                modified_by: { name: string; id: string };
                name: string;
                id: string;
                editor_mode: string;
                favorite: false | true;
                content: string;
                mail_content: string;
              }
            | {
                created_time: string;
                modified_time: string;
                last_usage_time: string;
                folder: { name: string; id: string };
                module: { api_name: string; id: string };
                created_by: { name: string; id: string };
                modified_by: { name: string; id: string };
                name: string;
                id: string;
                editor_mode: string;
                category: string;
                favorite: false | true;
                content: string;
                active: false | true;
                mail_content: string;
              };
          inventory_details: { inventory_template: { id: string; name?: string } };
          data_subject_request: { id: string; type: string };
          attachments: { id: string }[];
          linked_record: {
            module: { api_name: string; id: string };
            name: string;
            id: string;
          };
        }[];
      },
    ) {
      const url = new URL(
        `https://zohoapis.com/crm/v8/${moduleName}/${id}/actions/send_mail`,
      );
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Zoho-oauthtoken " + auth.token,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 235 days ago