Mail
Draft Mail

Draft Mail

Draft Mail is a service that allows you to save your email drafts before sending them.


Get the client

import { getSecrecyClient } from '@secrecy/lib';
 
// Get the client
const client = getSecrecyClient('prod');

updateDraft()

Update a draft mail.

const response = await client.mail.updateDraft('MAIL_ID', {
  subject: 'This is a test',
  body: 'This is the body of the test',
  files: [
    {
      id: 'FILE_ID',
      name: 'test.txt',
    },
  ],
  recipientsIds: ['RECIPIENT_ID_1', 'RECIPIENT_ID_2'],
  replyTo: 'MAIL_ID',
});
 
if (!response) {
  throw new Error(`Error`);
}
 
switch (response.__typename) {
  case 'ErrorAccessDenied':
    throw new Error(`Access Denied`);
  case 'ErrorNotFound':
    throw new Error(`Not Found`);
  case 'ErrorBasic':
    throw new Error(`Error`);
  case 'SuccessResponse': {
    const draftMail = response.data;
    // Do something with the draft mail
  }
}

Parameters

ParameterDescriptionTypeDefault
MAIL_IDThe ID of the draft mail to updatestringrequired
subjectThe subject of the mailstringrequired
bodyThe body of the mailstringrequired
filesThe files to attach to the mail{ id: string; name: string }[]required
recipientsIdsId or email of the recipients. If an email is not use by a Secrecy user, it will be invited to join Secrecy to read the mail.string[]required
replyToThe ID of the mail to reply tostring-

deleteDraft()

Delete a draft mail.

const response = await client.mail.deleteDraft('MAIL_ID');
 
if (!response) {
  throw new Error(`Error`);
}
 
switch (response.__typename) {
  case 'ErrorAccessDenied':
    throw new Error(`Access Denied`);
  case 'SuccessResponse': {
    const boolean = response.data;
    // Do something with the boolean
  }
}

sendDraft()

Send a draft mail to the recipients.

const response = await client.mail.sendDraft(
  'DRAFT_MAIL_ID',
  'CUSTOM_MESSAGE_OPTIONAL'
);
 
if (!response) {
  throw new Error(`Error`);
}
 
switch (response.__typename) {
  case 'ErrorAccessDenied':
    throw new Error(`Access Denied`);
  case 'ErrorBasic':
    throw new Error(`Error`);
  case 'SuccessResponse': {
    const boolean = response.data;
    // Do something with the boolean
  }
}

Parameters

ParameterDescriptionTypeDefault
draftMailIdThe id of the draft mailstringrequired
customMessageThe custom message will be sent to the external recipients in plain text.string-

createDraft()

Create a draft mail.

const response = await client.mail.createDraft({
  subject: 'Subject of the mail',
  body: 'Body of the email',
  files: [
    {
      id: 'FILE_ID',
      name: 'test.txt',
    },
  ],
  recipientsIds: ['RECIPIENT_ID_1', 'RECIPIENT_ID_2'],
  replyTo: 'MAIL_ID',
});
 
if (!response) {
  throw new Error(`Error`);
}
 
switch (response.__typename) {
  case 'ErrorAccessDenied':
    throw new Error(`Access Denied`);
  case 'ErrorBasic':
    throw new Error(`Error Basic`);
  case 'SuccessResponse': {
    const draftMail = response.data;
    // Do something with the draft mail
  }
}

Parameters

ParameterDescriptionTypeDefault
subjectThe subject of the mailstringrequired
bodyThe body of the mailstringrequired
filesThe files to attach to the mail{ id: string; name: string }[]required
recipientsIdsId or email of the recipients. If an email is not use by a Secrecy user, it will be invited to join Secrecy to read the mail.string[]required
replyToThe ID of the mail to reply tostring-

draftMails()

Return the list of draft mails.

const response = await client.mail.draftMails();
 
if (!response) {
  throw new Error(`Error`);
}
 
switch (response.__typename) {
  case 'ErrorNotFound':
    throw new Error(`Not found`);
  case 'SuccessResponse': {
    const draftMails = response.data;
    // Do something with the draft mails
  }
}