Documentation
Client SDK
Mail

Secrecy mail

The Secrecy Mail is a service that allows you to send secure emails to other users of Secrecy. Like a data transfer service, Sercrecy mail lets you attach files. These attachments are fully encrypted. You can also send emails to to people who don't have Secrecy accounts yet, but these emails it's an invitation to register on Secrecy to decrypt the message.

How Secrecy mail works

Just like a conventional mailbox, Secrecy's mail service includes all the functions inherent in managing a mailbox: draft management, management of read and unread mail, trash management and mail counter.

Sending messages is not limited to Secrecy account holders only. In addition, the Secrecy mail service includes the ability to send encrypted emails to external email addresses. In this case, the mail is put on hold with a status of unread until the recipient has registered for a Secrecy account.


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.


All three methods take a pagination object. Pass an empty object {} to use the server defaults.

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 ({
  page,
  perPage,
}: {
  page?: number;
  perPage?: number;
}): 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({
      page,
      perPage,
    });
    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 ({
  page,
  perPage,
}: {
  page?: number;
  perPage?: number;
}): 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.mail.sentMails({ page, perPage });
    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 ({
  page,
  perPage,
}: {
  page?: number;
  perPage?: number;
}): 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.mail.draftMails({ page, perPage });
    return draftMails;
  } catch (error) {
    console.error(error);
    return null;
  }
};