Documentation
SDK client
Modifier un brouillon

Modifier un brouillon de courrier

La méthode secrecyClient.mail.updateDraft permet d'effectuer des mises à jour partielles de brouillons de courrier électronique de manière sécurisée à l'aide de secrecyClient. Elle accepte un objet de courrier partiel de type NewMail comme argument, qui comprend des détails comme le subject, body, recipients, tout fichier de l'expéditeur SenderFiles, et un replyToId facultatif. La fonction vérifie d'abord si secrecyClient est disponible, et renvoie null si ce n'est pas le cas. Si secretClient est disponible, elle appelle secrecyClient.mail.updateDraft avec les propriétés de l'objet mail pour mettre à jour le brouillon et renvoie le DraftMail résultant.

mail.ts
type NewMail = {
  subject: string;
  body: string;
  replyToId: string | null;
  recipients: string[];
  senderFiles: {
    id: string;
    name: string;
  }[];
};
const updateDraftMail = async ({
  id,
  mail,
}: {
  id: string;
  mail: Partial<NewMail>;
}): Promise<DraftMail | null> => {
  // First we need to check if the secrecyClient is available
  if (!secrecyClient) {
    return null;
  }
 
  try {
    // return the updated draft mail
    const updatedDraftMail = await secrecyClient.mail.updateDraft(id, mail);
    return updatedDraftMail;
  } catch (error) {
    console.error(error);
    return null;
  }
};