Send Email

Learn how to send messages with Unipile

Feature available for : Google, Microsoft, IMAP

Send an email

Use the POST emails Method or use the appropriate SDK Method, to send an email to every recipient.

curl --request POST \
  --url https://{YOUR_DSN}/api/v1/emails \
  --header 'Content-Type: multipart/form-data' \
  --header 'X-API-KEY: {YOUR_ACCESS_TOKEN}' \
  --form account_id=kzAxdybMQ7ipVxK1U6kwZw \
  --form 'subject=Hello from Unipile' \
  --form 'body=Hello, this is a test email from Unipile' \
  --form 'to=[
	{
		"display_name": "John Doe",
		"identifier": "[email protected]"
	}
]' \
  --form 'cc=[
	{
		"display_name": "Jane Doe",
		"identifier": "[email protected]"
	}
]' \
const email: SendEmailInput = {
  account_id: "kzAxdybMQ7ipVxK1U6kwZw",
  to: [
    {
      display_name: "John Doe",
      identifier: "[email protected]",
    },
  ],
  cc: [
    {
      display_name: "Jane Doe",
      identifier: "[email protected]",
    },
  ],
  subject: "Hello from Unipile",
  body: "Hello, this is a test email from Unipile",
}

await client.email.send(email)

Send attachments

You can provide an additional attachment to the request body to send attachments along your email.

curl --request POST \
  --url https://{YOUR_DSN}/api/v1/emails \
  --header 'Content-Type: multipart/form-data' \
  --header 'X-API-KEY: {YOUR_ACCESS_TOKEN}' \
  --form account_id=kzAxdybMQ7ipVxK1U6kwZw \
  --form 'subject=Hello from Unipile' \
  --form 'body=Hello, this is a test email from Unipile' \
  --form 'to=[
	{
		"display_name": "John Doe",
		"identifier": "[email protected]"
	}
]' \
  --form 'attachments=@C:\Documents\cute_dog.png'
const filePath = "C:\\Documents\\cute_dog.png";
const buffer = await fs.promises.readFile(filePath);

const attachment: [string, Buffer] = [ path.basename(filePath), buffer ];

const email: SendEmailInput = {
  account_id: "kzAxdybMQ7ipVxK1U6kwZw",
  to: [
    {
      display_name: "John Doe",
      identifier: "[email protected]",
    },
  ],
  subject: "Hello from Unipile",
  body: "Hello, this is a test email from Unipile",
  attachments: [ attachment ],
}

await client.email.send(email)

Send with custom headers

You can set additional custom headers using the "X-" syntax.

curl --request POST \
  --url https://{YOUR_DSN}/api/v1/emails \
  --header 'Content-Type: multipart/form-data' \
  --header 'X-API-KEY: {YOUR_ACCESS_TOKEN}' \
  --form account_id=kzAxdybMQ7ipVxK1U6kwZw \
  --form 'subject=Hello from Unipile' \
  --form 'body=Hello, this is a test email from Unipile' \
  --form 'to=[
	{
		"display_name": "John Doe",
		"identifier": "[email protected]"
	}
]' \
  --form 'cc=[
	{
		"display_name": "Jane Doe",
		"identifier": "[email protected]"
	}
]' \
  --form 'custom_headers=[
    {
      "name": "X-My-Custom-Header",
      "value": "Example value"
    }]'
const email: SendEmailInput = {
  account_id: "kzAxdybMQ7ipVxK1U6kwZw",
  to: [
    {
      display_name: "John Doe",
      identifier: "[email protected]",
    },
  ],
  cc: [
    {
      display_name: "Jane Doe",
      identifier: "[email protected]",
    },
  ],
  subject: "Hello from Unipile",
  body: "Hello, this is a test email from Unipile",
  custom_headers: [
    {
      name: "X-My-Custom-Header",
      value: "Example value",
    }
  ]
}

await client.email.send(email)

Reply to an email

You can set additional parameter "reply_to" with unipile internal "id" of email

curl --request POST \
  --url https://{YOUR_DSN}/api/v1/emails \
  --header 'Content-Type: multipart/form-data' \
  --header 'X-API-KEY: {YOUR_ACCESS_TOKEN}' \
  --form account_id=kzAxdybMQ7ipVxK1U6kwZw \
  --form 'subject=Re:Hello from Unipile' \
  --form 'body=Hello, this is a test reply from Unipile' \
  --form 'to=[
	{
		"display_name": "John Doe",
		"identifier": "[email protected]"
	}
]' \
  --form 'reply_to=X4R9___qXQKIu80oAF0lJA

Personalize "from"

You can set additional parameter "from" with your display name and/or alias configured on your provider.

curl --request POST \
  --url https://{YOUR_DSN}/api/v1/emails \
  --header 'Content-Type: multipart/form-data' \
  --header 'X-API-KEY: {YOUR_ACCESS_TOKEN}' \
  --form account_id=kzAxdybMQ7ipVxK1U6kwZw \
  --form 'subject=Hello from Unipile' \
  --form 'body=Hello, this is a test email from Unipile' \
   --form 'from={
		"display_name": "Jake Doe",
		"identifier": "[email protected]"
	}' \
  --form 'to=[
	{
		"display_name": "John Doe",
		"identifier": "[email protected]"
	}
]' \
  --form 'cc=[
	{
		"display_name": "Jane Doe",
		"identifier": "[email protected]"
	}
]' \

Tracking options

You can receive a webhook when an email is read or a link is clicked.

curl --request POST \
  --url https://{YOUR_DSN}/api/v1/emails \
  --header 'Content-Type: multipart/form-data' \
  --header 'X-API-KEY: {YOUR_ACCESS_TOKEN}' \
  --form account_id=kzAxdybMQ7ipVxK1U6kwZw \
  --form 'subject=Hello from Unipile' \
  --form 'body=Hello, this is a test email from Unipile' \
  --form 'to=[
	{
		"display_name": "John Doe",
		"identifier": "[email protected]"
	}
]' \
  --form 'cc=[
	{
		"display_name": "Jane Doe",
		"identifier": "[email protected]"
	}
]' \
  --form 'tracking_options={
  "opens": true,
	"links": true,
	"label": "myownid"
}'

const email: SendEmailInput = {
  account_id: "kzAxdybMQ7ipVxK1U6kwZw",
  to: [
    {
      display_name: "John Doe",
      identifier: "[email protected]",
    },
  ],
  cc: [
    {
      display_name: "Jane Doe",
      identifier: "[email protected]",
    },
  ],
  subject: "Hello from Unipile",
  body: "Hello, this is a test email from Unipile",
  tracking_options: {
    "opens": "true",
    "links": "true",
    "label": "myownid"
  }
}

await client.email.send(email)