Mail
Getting started with the mail

Getting started with the mail

Mail is Email !

To facilitate mail management, mail is divided into three categories, MailType : sent, received, draft. This distinction into three types (draft, received, sent) makes it possible to recreate the classic behavior of an e-mail inbox.

The MailType property is equal to : sent | received | draft |

Secrecy mail also includes trash management, with operations for temporary and permanent deletion of mail.


Get received mails

The secrecyClient.mail.receivedMails is a method that retrieves a list of received mails. It first checks if secrecyClient is available; if not, it returns null. If secrecyClient exists, it attempts to fetch the received mails. If the retrieval is successful, it returns the list of received mails which type is ReceivedMail.

mail-received.ts
const getMyReceivedMails = async (): Promise<ReceivedMail[] | null> => {
  // First we need to check if the secrecyClient is available
  if (!secrecyClient) {
    return null;
  }
 
  try {
    // Get received mails
    const receivedMails = await secrecyClient.mail.receivedMails();
    return receivedMails;
  } catch (error) {
    console.error(error);
    return null;
  }
};

Get sent mails

The secrecyClient.mail.sentMails is a method that retrieves a list of sent mails. It first checks if secrecyClient is available; if not, it returns null. If secrecyClient exists, it attempts to fetch the sent mails. If the retrieval is successful, it returns the list of sent mails which type is SentMail.

mail-sent.ts
const getMySentMails = async (): Promise<SentMail[] | null> => {
  // First we need to check if the secrecyClient is available
  if (!secrecyClient) {
    return null;
  }
 
  try {
    // Get sent mails
    const sentMails = await secrecyClient.sentMails();
    return sentMails;
  } catch (error) {
    console.error(error);
    return null;
  }
};

Get draft mails

The secrecyClient.mail.draftMails is a method that retrieves a list of draft mails. It first checks if secrecyClient is available; if not, it returns null. If secrecyClient exists, it attempts to fetch the draft mails. If the retrieval is successful, it returns the list of draft mails which type is DraftMail.

mail-draft.ts
const getMyDraftMails = async (): Promise<DraftMail[] | null> => {
  // First we need to check if the secrecyClient is available
  if (!secrecyClient) {
    return null;
  }
 
  try {
    // Get draft mails
    const draftMails = await secrecyClient.draftMails();
    return draftMails;
  } catch (error) {
    console.error(error);
    return null;
  }
};