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
Parameter | Description | Type | Default |
---|---|---|---|
MAIL_ID | The ID of the draft mail to update | string | required |
subject | The subject of the mail | string | required |
body | The body of the mail | string | required |
files | The files to attach to the mail | { id: string; name: string }[] | required |
recipientsIds | Id 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 |
replyTo | The ID of the mail to reply to | string | - |
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
Parameter | Description | Type | Default |
---|---|---|---|
draftMailId | The id of the draft mail | string | required |
customMessage | The 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
Parameter | Description | Type | Default |
---|---|---|---|
subject | The subject of the mail | string | required |
body | The body of the mail | string | required |
files | The files to attach to the mail | { id: string; name: string }[] | required |
recipientsIds | Id 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 |
replyTo | The ID of the mail to reply to | string | - |
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
}
}