Receive Emails: Drafts

Save Draft

Save an email in Drafts without sending it. It opens in the webmail like any other draft, and you can send it later with send_draft.

POSThttps://g.sendcorex.com/v1command: save_draft
i

A draft can be incomplete: every field is optional. What you send is checked (a to that is not an email fails), what you leave out is not.

!

To edit a draft, send its draft_id. Fields you leave out are kept (body, recipients, subject, attachments, follow-up). Every save returns a NEW draft_id and the old one stops working, so always keep the last one.

i

If track_opens or track_clicks is omitted, the draft keeps the choice it already had. send_draft and the scheduled send use that choice.

i

Recipients who refused tracking on the preferences page are never tracked, even with true.

Arguments

  • draft_idstringoptional

    Edit this draft instead of creating a new one.

  • modestringoptional

    new (default), reply or forward. When editing, the draft keeps its mode.

  • idstringoptional

    The original message, for reply and forward. The subject defaults to Re: / Fwd: original.

  • tostring | string[]optional

    Recipient, or an array of up to 30 for new (paid plans). Ignored for reply: it goes to the sender of the original.

  • ccstring[]optional

    Visible copies.

  • bccstring[]optional

    Hidden copies.

  • subjectstringoptional

    Subject.

  • htmlstringoptional

    HTML body. Or text, or template_id.

  • textstringoptional

    Plain text body, turned into simple HTML.

  • template_idstringoptional

    Fill the body (and the subject) from a template.

  • variablesobjectoptional

    Values for the template variables, like { "first_name": "Ana" }.

  • followup_after_hoursnumber | nulloptional

    Remind you if nobody replies this many hours after it is sent (up to 8760). null removes it.

  • attachmentsobject[]optional

    Files to attach: [{ file_name, content, content_type }], content in base64. They are added to the files the draft already has.

  • compose_uidstringoptional

    Files uploaded before with upload_attachment or Upload Large File.

  • attachment_idsstring[]optional

    Which of the uploaded files to use. Without it, all of them.

  • track_opensbooleanoptional

    Track when each recipient opens the email (invisible pixel). Default true.

  • track_clicksbooleanoptional

    Track clicks on the links (each link goes through a redirect). Default true.

  • unsubscribebooleanoptional

    Add an unsubscribe link. Put [unsubscribe] in the body (as a link href or as plain text) where the link should go; without it, a default line is added at the end. Default false.

  • audiencestringoptional

    Send to an audience instead of addresses: subscribed, opened, clicked, both, seg:<segment_id> or msg:<message_uid>:opened|clicked|not_opened. to becomes optional. Up to 5,000 people. The unsubscribe link is turned on and the email goes out as marketing. Paid plans.

Quick start

import axios from 'axios';

const response = await axios.post(
  'https://g.sendcorex.com/v1',
  {
    commands: [
      {
        command: "save_draft",
        args: {
          to: "ana@client.com",
          subject: "Proposal",
          html: "<p>Hi Ana, here is the proposal.</p>"
        }
      }
    ]
  },
  { headers: { Authorization: process.env.SENDCOREX_TOKEN } },
);

const [result] = response.data.results;
if (result.type !== 'SUCCESS') throw new Error(`${result.code}: ${result.message}`);
console.log(result.data);

Response

{
  "type": "SUCCESS",
  "results": [
    {
      "command": "save_draft",
      "id": "0",
      "type": "SUCCESS",
      "data": {
        "draft_id": "Vj0xRFJBRlQx",
        "thread_id": "thr_9a1c4e72"
      }
    }
  ]
}

Response fields

  • draft_id

    The draft. Use it to edit, read, send or delete it. Changes on every save.

  • thread_id

    The conversation the draft belongs to.

Edit a draft

Only the subject changes here. The body, recipients and attachments stay as they were.

Request body

{
  "commands": [
    {
      "command": "save_draft",
      "args": {
        "draft_id": "Vj0xRFJBRlQx",
        "subject": "Proposal (v2)"
      }
    }
  ]
}

Errors

HTTP-level errors return type, code and message. Errors marked CMD come back inside the command result, with HTTP 200.

  • 401TOKEN_EXPIRED

    The access token has expired. Call Refresh Token and repeat the request.

  • 401INVALID_TOKEN

    The token is malformed, unknown or revoked.

  • 429RATE_LIMITED

    More than 15 requests/s or 15 in flight for the same IP + mailbox. Wait the number of seconds in Retry-After.

  • CMDINVALID_AUDIENCE

    The audience is not valid: unknown group, a segment of another mailbox or a message this mailbox didn’t send.

  • CMDINVALID_ARGS

    A required argument is missing or invalid.

  • CMDPAID_PLAN_REQUIRED

    More than one address in `to` needs a paid plan.

  • CMDTOO_MANY_RECIPIENTS

    `to` has more than 30 addresses.

  • CMDDRAFT_NOT_FOUND

    The draft does not exist anymore: it was sent, deleted, or saved again (every save returns a new draft_id).

  • CMDMISSING_TARGET

    Reply and forward need the original email, and it must still exist.

  • CMDINVALID_RECIPIENT

    The recipient is missing or not a valid email.

  • CMDINVALID_CCADDRESS

    One of the cc addresses is not a valid email.

  • CMDINVALID_BCCADDRESS

    One of the bcc addresses is not a valid email.

  • CMDRECIPIENT_LIMIT_EXCEEDED

    to, cc and bcc together have more than 50 addresses.

  • CMDINVALID_ATTACHMENT

    An attachment content is not valid base64.

  • CMDFILE_BLOCKED

    A file was blocked by the security scan.

  • CMDATTACHMENTS_TOO_LARGE

    The attachments of the email add up to more than 25 MB, or the mailbox already has 500 MB of uploads waiting to be sent.

  • CMDATTACHMENT_MISSING

    An uploaded attachment no longer exists (uploads not sent within 48 hours, and not used by a draft or scheduled email, are deleted). Upload it again.

  • CMDINTERNAL

    Server error. The detail is only written to the server log.