Mail
Delete definitively mails

Remove permanently mails from trash

The secrecyClient.mail.deleteTrash and secrecyClient.mail.emptyTrash methods makes a hard delete of a mails. That means that the mails are permanently deleted.

Delete mails by ID

The secrecyClient.mail.deleteTrash is a method which attempts to delete permanently specified mails by their IDs, returning a boolean status indicating whether the operation was successful. As argument it takes the mailsIds array as the parameter ids. In other words, selected mails will be removed permanently from the trash

mail.ts
const deleteMailsById = async (mailsIds: string[]): Promise<boolean> => {
  // First we need to check if the secrecyClient is available
  if (!secrecyClient) {
    return false;
  }
 
  try {
    // return true if the mails have been deleted
    const isDeleted = await client.mail.deleteTrash({ ids: mailsIds });
    return isDeleted;
  } catch (error) {
    console.error(error);
    return false;
  }
};

Empty the trash

As the method's name explicitly indicates secrecyClient.mail.emptyTrash is the method which attempts to clear the trash folder of all emails. All emails from the trash will be permanently deleted. It returns a boolean status indicating whether the operation was successful.

mail.ts
const deleteAllMailsFromTrash = async (): Promise<boolean> => {
  // First we need to check if the secrecyClient is available
  if (!secrecyClient) {
    return false;
  }
 
  try {
    // return true if the trash has been emptied
    const isDeleted = await secrecyClient.mail.deleteDraft();
    return isDeleted;
  } catch (error) {
    console.error(error);
    return false;
  }
};