Mail
Send mails to non-registered users

The case of non-registered users

The Secrecy mail service handles recipients who don't yet have a Secrecy account. The usual send mails methods manage the sending of mails to unregistered users. Users without an account will receive an email, in the mailbox of their mail provider inviting them to join Secrecy to read the mail. In this case, the secrecy mail is put on hold, to ensure that the mail is accessible to the user once he has his secrecy account you simply need to call the following additional method: secrecyClient.mail.sendWaitingEmails.

Send mails to non-registered users

We recommend that you use the secrecyClient.mail.sendWaitingEmails repeatedly, to avoid a time lag between the provision of the mail and the Secrecy registration of the recipient. This is why we have passed the function as a callback in the setInterval method. In our example, we have set the interval to 5 minutes.

app.ts
useEffect(() => {
  // First we need to check if the secrecyClient is available
  if (!secrecyClient) {
    return;
  }
  // Define the interval function
  const intervalId = setInterval(() => {
    void secrecyClient.mail.sendWaitingEmails();
  }, 60000 * 5); // 5 minutes
 
  // Clean up the interval on component unmount
  return () => clearInterval(intervalId);
}, [secrecyClient]);

Get waiting received mails

On the other hand, you need to make sure that the recipient retrieves any mail that has been put on hold. The secrecyClient.mail.waitingReceivedMails is the method that retrieves a list of received mails that has been put on hold. It first checks if secrecyClient is available; if not, it returns null. If secrecyClient exists, it attempts to fetch the waiting received mails. If the retrieval is successful, it returns the list of received mails which type is WaitingReceivedMail.

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