Retrieve emails
Learn how to retrieve emails using Unipile API.
List emails
To list all emails in a specific folder, or with a specific Gmail label, use List folder Emails method and provide the folder ID.
const { data } = await emailsApi.getFolderEmailsList({
path: {
account_id: "acc_123456789",
folder_id: "folder_id",
},
query: {
limit: 20,
},
});emails = emails_api.get_folder_emails_list(
"acc_123456789",
"folder_id",
limit=20,
)curl --request GET \
--url https://api.unipile.com/v2/account_id/folders/folder_id/emails \
--header 'accept: application/json'If you need to, you can even list emails across all folders using List all Emails.
This feature is not supported for IMAP accounts unless you enable Initial Sync
const { data } = await emailsApi.getEmailsList({
path: {
account_id: "acc_123456789",
},
query: {
limit: 20,
},
});emails = emails_api.get_emails_list(
"acc_123456789",
limit=20,
)curl --request GET \
--url https://api.unipile.com/v2/account_id/emails \
--header 'accept: application/json'Get a specific email
To get a specific email, use Get an Email method and provide the Email ID.
const { data } = await emailsApi.getEmail({
path: {
account_id: "acc_123456789",
email_id: "email_id",
},
});email = emails_api.get_email("acc_123456789", "email_id")curl --request GET \
--url https://api.unipile.com/v2/account_id/emails/email_id \
--header 'accept: application/json'
RecommendationListing full emails can be slow and use more provider quota when the data is not cached. To improve performance, set
meta_onlytotruewhen listing emails to fetch only partial data (enough for displaying in a UI list).
When a full email is needed, retrieve it using Get an Email.
Download attachments
If an email contains attachments, only metadata useful for display are present in the Email object.
Use Get an Email Attachment to download the file itself by providing the Email ID and Attachment ID.
const attachment = await emailsApi.getAttachment1({
path: {
account_id: "acc_123456789",
email_id: "email_id",
attachment_id: "attachment_id",
},
});attachment = emails_api.get_attachment1(
"acc_123456789",
"email_id",
"attachment_id",
)curl --request GET \
--url https://api.unipile.com/v2/account_id/emails/email_id/attachments/attachment_idRetrieve a conversation thread
Use Get an Email Thread with the thread identifier returned by an email to retrieve its conversation. Keep thread_id, the email id, and the RFC822 message_id separate. IMAP may derive a thread identifier from mail headers when the server does not supply one, so it may differ between messages and may be absent.
const { data } = await emailsApi.getThread({
path: {
account_id: "acc_123456789",
thread_id: "thread_id",
},
});data = emails_api.get_thread(
account_id='acc_123456789',
thread_id='thread_id',
)curl --request GET \
--url "https://api.unipile.com/v2/acc_123456789/threads/thread_id" \
--header 'X-API-KEY: YOUR_API_KEY'List available senders
For Gmail and Outlook, use List all Email Senders to discover sender addresses before composing an email. This method is not relevant to IMAP in the availability matrix. Use the sender information with Send an Email; listing an address does not grant additional sending permissions.
const { data } = await emailsApi.getEmailSenders({
path: {
account_id: "acc_123456789",
},
});import requests
response = requests.get(
"https://api.unipile.com/v2/acc_123456789/email-senders",
headers={"X-API-KEY": "YOUR_API_KEY"},
timeout=30,
)
response.raise_for_status()
data = response.json()curl --request GET \
--url "https://api.unipile.com/v2/acc_123456789/email-senders" \
--header 'X-API-KEY: YOUR_API_KEY'Updated 8 days ago