Sign In Try it free

Creating a Draft Email


Email model

See email model in the reference.

Simple email

Draft emails are created on the underlying provider and so can be interacted with in the same way on any device or application connected to your accounts. As with all other private data, they are not stored on the WorkAPI platform.

As with the creation of any item via the WorkAPI, an `integraiton_id` is required.

Examples
token = "<user's token>"
client = LivilApi::Service.new(token)

email = LivilApi::Email.new(
  integration_id: 'abc17171923def19098',
  subject: 'This is a test draft email',
  to_recpients: [{ address: 'test@work-api.com' }],
  body:{ 
    plain_text: ['this is a plan text part', 'and another'], 
    html: ['<b>this</b> is <i>HTML!</i>']
  }
)

response = client.create_draft(email: email)

response
# => LivilApi::Email(id: '...', subject: 'This is a test draft email', ...)

Examples

my_file = File.open('/path/to/file.txt')
attachment = LivilApi::EmailAttachment.new 
attachment.attach('a-file-name.txt', my_file)

email = LivilApi::Email.new(
  integration_id: 'abc17171923def19098',
  subject: 'This is a test draft email with an attachment',
  to_recpients: [{ address: 'test@livil.co' }],
  body:{ 
    plain_text: ['the file you requested is attached!'], 
  },
  attachments: [attachment]
)


response = client.send_email(email: email)

response
# => LivilApi::Email(id: '...', subject: 'This is a test draft email with an attachment', ...)

Email with attachments (using remote file from a WorkAPI integration)

Attachments may also come from other sources within the WorkAPI, such as a Google Drive or OneDrive account.

This section will be updated when the file integration is in place.

Examples

my_file = service.get_file(file_id: 'abcd123') # TODO: confirm syntax

my_file # => LivilApi::File(remote_id: 'abcd123', integration_id: '12377abcd72f', filename: 'something.doc')

attachment = LivilApi::EmailAttachment.new 
attachment.attach('a-file-name.txt', my_file)

email = LivilApi::Email.new(
  integration_id: 'abc17171923def19098',
  subject: 'This is an email with an attachment',
  to_recpients: [{ address: 'test@livil.co' }],
  body:{ 
    plain_text: ['the file you requested is attached!'], 
  },
  attachments: [attachment]
)


response = client.send_email(email: email)

response
# => :accepted

Updating an existing draft

The draft update process replaces the original rather than attempting to update it in-place. Any attributes which are left out of the update payload will be `nil` or equivalent on the updated draft. This also applies to attachments.

Examples

          token = "<user's token>"
client = LivilApi::Service.new(token)

draft_email_id = 'XYZ...'

email = LivilApi::Email.new(
  id: draft_email_id,
  # `integration_id` is not necessary here as it is encoded in the draft ID
  subject: 'This is an updated test draft email',
  to_recpients: [{ address: 'test@livil.co' }],
  body:{ 
    plain_text: ['this is a plan text part', 'and another'], 
    html: ['<b>this</> is <>HTML!</i>']
  }
)

response = client.update_draft(email_id: draft_email_id, email: email)

response
# => LivilApi::Email(id: '...', subject: 'This is an updated test draft email', ...)

First 50,000 requests are free every month