This guide assumes you've already done the following:
See mailbox model in the reference.
Without providing any additional parameters, the email list endpoint will return the latest [TBC] emails across all email accounts.
token = "<user's token>"
client = LivilApi::Service.new(token)
"bu"bku
emails = client.list_emails
emails
# => [LivilApi::Email(id: '...', subject: 're: An important message', ...), ...]
Pagination and count information is available in the meta
hash.
NOTE:
The total_results
from some providers are estimates, so this number should not be treated 100% accurate.
emails = client.list_emails
emails.meta
# => <OpenStruct next_page="abcd23kjasdkfjlasdjf", total_results=34>
There are a number of filters which may be applied to the request in order to limit the returned results.
NOTE:
Unless othewise specified below, all filtering and searching is performed by the provider APIs. Contents are not scanned by the WorkAPI system.
The email list endpoint supports the following standard parameters:
limit
: the number of records to return
NOTE:
Sorting and ordering is not currently possible.
For pagination, combine limit
with the date range filters.
The mailbox_id
refers to the WorkAPI mailbox ID.
Any emails that appear in a mailbox with one of the specified mailbox_ids
will be included in the result set (subject to pagination).
Emails may have multiple mailboxes so multiple IDs may be present.
NOTE:
In Gmail, an email which has been both sent and received by the same account will contains IDs for both the Inbox and Sent mailboxes.
emails = client.list_emails(mailbox_ids: ['ABCDE...'])
emails
# => [LivilApi::Email(id: '...', ..., mailboxes: [LivilApi::Mailbox(id: 'ABCDE...')])]
The date range filters by the `received_at` date and time. Any emails that were received between those dates will be included in the result set (subject to pagination).
emails = client.list_emails(date_from: '2019-10-01T00:00z', date_until: '2019-12-31T00:00z')
emails
# => [LivilApi::Email(id: '...', ..., received_at: '2019-11-01T10:30z')]
Specific contact information can be matched against emails in your account by passing a contact object.
contact = LivilApi::Contact.new(first_name: 'Dave', last_name: 'Smith')
contact.email_addresses << LivilApi::ContactEmailAddress.new(address: 'dave.smith@livil.co')
emails = client.list_emails(contact: contact)
emails
# => [LivilApi::Email(id: '...', ..., sender: 'Dave Smith ')]
A keyword search is performed on emails in the specified mailboxes (default: all).
emails = client.list_emails(search_text: 'your subscription')
emails
# => [LivilApi::Email(id: '...', body: [LivilApi::EmailBody(plain_text: '... renew your subscription today...')])]